Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity needs to be set if initial lifecycle state is resumed

Hello I am trying to integrate react-native application inside inside my native android. I Follow steps give following links

https://facebook.github.io/react-native/docs/integration-with-existing-apps https://medium.com/mindorks/react-native-integration-with-existing-app-f2757c2e672d

Here is my react activity code

super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.
        builder()
        .setApplication(getApplication())
        .setBundleAssetName("index.android.bundle")
        .setJSMainModulePath("index.android")
        .addPackage(new MainReactPackage())
        .setUseDeveloperSupport(BuildConfig.DEBUG)
        .setInitialLifecycleState(LifecycleState.RESUMED)
        .build();
mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null);
setContentView(mReactRootView);

But I am getting following error when my react activity get launched

java.lang.AssertionError: Activity needs to be set if initial lifecycle state is resumed
        at com.facebook.infer.annotation.Assertions.assertNotNull(Assertions.java:35)
        at com.facebook.react.ReactInstanceManagerBuilder.build(ReactInstanceManagerBuilder.java:250)
        at com.skw.android_react_2.MyReactActivity.onCreate(MyReactActivity.java:35)
        at android.app.Activity.performCreate(Activity.java:7383)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3256)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3411)
        at android.app.ActivityThread.-wrap12(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1994)
        at android.os.Handler.dispatchMessage(Handler.java:108)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:7529)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

how to resolve this?

like image 205
dev_swat Avatar asked Jul 09 '19 06:07

dev_swat


People also ask

What are the basic concepts of activity lifecycle?

Activity-lifecycle concepts. To navigate transitions between stages of the activity lifecycle, the Activity class provides a core set of six callbacks: onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy(). The system invokes each of these callbacks as an activity enters a new state.

How do I navigate between stages of the activity lifecycle?

To navigate transitions between stages of the activity lifecycle, the Activity class provides a core set of six callbacks: onCreate () , onStart () , onResume () , onPause () , onStop (), and onDestroy (). The system invokes each of these callbacks as an activity enters a new state. Figure 1 presents a visual representation of this paradigm.

How is the process lifecycle tied to the states of activities?

For more information about how the lifecycle of a process is tied to the states of the activities in it, see the Process Lifecycle section of that page. A user expects an activity’s UI state to remain the same throughout a configuration change, such as rotation or switching into multi-window mode.

What are the 6 callbacks of activity lifecycle?

Activity-lifecycle concepts To navigate transitions between stages of the activity lifecycle, the Activity class provides a core set of six callbacks: onCreate (), onStart (), onResume (), onPause (), onStop (), and onDestroy (). The system invokes each of these callbacks as an activity enters a new state.


1 Answers

You can fix this in two ways. Either set the activity:

mReactInstanceManager = ReactInstanceManager.builder()
    .setApplication(getApplication())
    .setCurrentActivity(this) // <== *** HERE ***
    .setBundleAssetName("index.android.bundle")
    .setJSMainModulePath("index.android")
    .addPackage(new MainReactPackage())
    .setUseDeveloperSupport(BuildConfig.DEBUG)
    .setInitialLifecycleState(LifecycleState.RESUMED)
    .build();

...or change the initial life cycle state to something other than LifecycleState.RESUMED:

mReactInstanceManager = ReactInstanceManager.builder()
    .setApplication(getApplication())
    .setBundleAssetName("index.android.bundle")
    .setJSMainModulePath("index.android")
    .addPackage(new MainReactPackage())
    .setUseDeveloperSupport(BuildConfig.DEBUG)
    .setInitialLifecycleState(LifecycleState.BEFORE_CREATE) // <== *** HERE ***
    .build();
like image 159
Petter Hesselberg Avatar answered Sep 22 '22 13:09

Petter Hesselberg