react-native-maps集成问题与react-native 0.19.0

时间:2016-02-07 13:44:19

标签: android react-native

根据添加react-native-maps的说明,添加到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)

这是反应本机代码中的异常源,DialogModule类:

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 但似乎没有反映在我的模拟器中运行的编译代码中。

还尝试将 LifecycleState.RESUMED 设置为 LifecycleState.BEFORE_RESUME ,但之后应用只会加载空白屏幕并且Dev菜单无法正常运行。

我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

您的其他活动是什么样的?我遇到了这个问题,但问题是我没有在我的活动中实现 DefaultHardwareBackBtnHandler

以下是它们的实施方式:

@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();
    }
}