我试图弄清楚如何通过桥接公开一种方法来“杀死”一个本机应用程序。这是我们挂载运行我们的js代码的活动的方式。
public void startReactApp(Activity activity, String configString) {
if (activity == null) {
Log.e("MobileSDK", "activity can't be null. returning.");
return;
}
MobileSDKActivity sdkact = new MobileSDKActivity();
sdkact.setConfigString(configString);
Intent intent = new Intent(activity, MobileSDKActivity.class);
activity.startActivity(intent);
// Send Events to React Native after 5 seconds of starting React app.
new Handler().postDelayed(new Runnable() {
public void run() {
// Send event to react native to enabled back button.
MyReactBridge.sendEnableBackButton();
}
}, 5000);
}
这是我在网上找到的解决方案。
void dismissReactActivity() {
if (this.myActivityReference.get() != null) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
public void run() {
((MobileSDKActivity) myActivityReference.get()).onBackPressed();
}
});
}
}
有没有一种方法,而无需调用onbackpressed