问题描述
根据添加react-native-maps的说明,添加到 MainActivity:
As per instructions of adding react-native-maps, adding to MainActivity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new AirPackage()) // <---- and This!
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "MelBike", null);
setContentView(mReactRootView);
}
我遇到了这个异常:
java.lang.AssertionError: Attached DialogModule to host with pending alert but no FragmentManager (not attached to an Activity).
at com.facebook.infer.annotation.Assertions.assertNotNull(Assertions.java:28)
at com.facebook.react.modules.dialog.DialogModule.onHostResume(DialogModule.java:199)
at com.facebook.react.bridge.ReactContext.onResume(ReactContext.java:140)
at com.facebook.react.ReactInstanceManagerImpl.moveReactContextToCurrentLifecycleState(ReactInstanceManagerImpl.java:761)
at com.facebook.react.ReactInstanceManagerImpl.setupReactContext(ReactInstanceManagerImpl.java:599)
at com.facebook.react.ReactInstanceManagerImpl.access$700(ReactInstanceManagerImpl.java:84)
at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.onPostExecute(ReactInstanceManagerImpl.java:187)
at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.onPostExecute(ReactInstanceManagerImpl.java:162)
at android.os.AsyncTask.finish(AsyncTask.java:651)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
这是 react native 代码中异常的来源,DialogModule 类:
This is the source of the exception in react native code, DialogModule class:
public void onHostResume() {
mIsInForeground = true;
// Check if a dialog has been created while the host was paused, so that we can show it now.
FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper();
Assertions.assertNotNull(
fragmentManagerHelper,
"Attached DialogModule to host with pending alert but no FragmentManager " +
"(not attached to an Activity).");
fragmentManagerHelper.showPendingAlert();
我试图注释掉 DialogModule 类中的断言并运行 react-native run-android,但它似乎没有反映在我的模拟器中运行的编译代码中.
I have tried to comment out the assertion in DialogModule class and run react-native run-android but it seems it was not reflected in compiled code that ran in my emulator.
还尝试将 LifecycleState.RESUMED 设置为 LifecycleState.BEFORE_RESUME,但随后应用只加载了空白屏幕并且开发菜单无法正常运行.
Also tried to set the LifecycleState.RESUMED to LifecycleState.BEFORE_RESUME but then the app only loads blank screen and Dev menu wasn't functioning properly.
我错过了什么吗?
推荐答案
您的 Activity 的其余部分是什么样的?我遇到了这个问题,但问题是我没有在我的活动中实现 DefaultHardwareBackBtnHandler.
What does the rest of your activity look like? I ran into this but the problem was that I was not implementing DefaultHardwareBackBtnHandler in my activity.
以下是它们的实现方式:
Here is how they are implemented:
@Override
protected void onPause() {
super.onPause();
if (mReactInstanceManager != null) {
mReactInstanceManager.onPause();
}
}
@Override
protected void onResume() {
super.onResume();
if (mReactInstanceManager != null) {
mReactInstanceManager.onResume( this, this );
}
}
@Override
public void onBackPressed() {
if (mReactInstanceManager != null) {
mReactInstanceManager.onBackPressed();
} else {
super.onBackPressed();
}
}
这篇关于react-native-maps 与 react-native 0.19.0 的集成问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!