Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Crash on killed app restore #114

Closed
Sroka opened this issue Jun 14, 2019 · 32 comments
Closed

[Android] Crash on killed app restore #114

Sroka opened this issue Jun 14, 2019 · 32 comments

Comments

@Sroka
Copy link

Sroka commented Jun 14, 2019

Hey, I am getting a crash on current version of this lib (^1.0.0-alpha.22)

2019-06-14 13:29:35.255 27866-27866/com.gelato.Optimalprint.dev E/AndroidRuntime: FATAL EXCEPTION: main Process: com.gelato.Optimalprint.dev, PID: 27866 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gelato.Optimalprint.dev/com.gelato.Optimalprint.MainActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.Screen$ScreenFragment: calling Fragment constructor caused an exception at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.Screen$ScreenFragment: calling Fragment constructor caused an exception at android.support.v4.app.Fragment.instantiate(Fragment.java:465) at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:50) at android.support.v4.app.FragmentState.instantiate(FragmentState.java:80) at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:3109) at android.support.v4.app.FragmentController.restoreAllState(FragmentController.java:158) at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:344) at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:85) at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:51) at android.app.Activity.performCreate(Activity.java:7009) at android.app.Activity.performCreate(Activity.java:7000) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6494)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)  Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:334) at android.support.v4.app.Fragment.instantiate(Fragment.java:443) at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:50)  at android.support.v4.app.FragmentState.instantiate(FragmentState.java:80)  at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:3109)  at android.support.v4.app.FragmentController.restoreAllState(FragmentController.java:158)  at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:344)  at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:85)  at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:51)  at android.app.Activity.performCreate(Activity.java:7009)  at android.app.Activity.performCreate(Activity.java:7000)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6494)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)  Caused by: java.lang.IllegalStateException: Screen fragments should never be restored at com.swmansion.rnscreens.Screen$ScreenFragment.<init>(Screen.java:23) at java.lang.reflect.Constructor.newInstance0(Native Method)  at java.lang.reflect.Constructor.newInstance(Constructor.java:334)  at android.support.v4.app.Fragment.instantiate(Fragment.java:443)  at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:50)  at android.support.v4.app.FragmentState.instantiate(FragmentState.java:80)  at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:3109)  at android.support.v4.app.FragmentController.restoreAllState(FragmentController.java:158)  at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:344)  at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:85)  at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:51)  at android.app.Activity.performCreate(Activity.java:7009)  at android.app.Activity.performCreate(Activity.java:7000)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6494)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

I guess this is happening because of this code in ScreenFragment:
public ScreenFragment() { throw new IllegalStateException("Screen fragments should never be restored"); }

It will happen to users only when the activity is killed in the background and then user tries to restore it. It is easily reproducible by setting "Don't keep Activities" in Developer options.

@grciqa
Copy link

grciqa commented Jul 8, 2019

I believe this is the same issue as #105 and #54

@m4r00p
Copy link

m4r00p commented Jul 9, 2019

Any luck guys with fixing this? (screens give really big boost the app but they crashing the app each time for the given scenario... ;()

@fontesrp
Copy link

fontesrp commented Aug 27, 2019

Any idea on how to solve/work-around this? I'm getting this error A LOT in my production build. Has anyone at least been able to find the line in this library that is causing the error?

Here are my dependencies:

  "dependencies": {
    "@react-native-community/async-storage": "^1.5.1",
    "@react-native-community/netinfo": "^4.1.2",
    "axios": "^0.19.0",
    "color": "^3.1.2",
    "formik": "^1.5.8",
    "himalaya": "^1.1.0",
    "qs": "^6.7.0",
    "react": "16.8.6",
    "react-native": "0.60.4",
    "react-native-awesome-card-io": "^0.8.2",
    "react-native-camera": "^3.0.0",
    "react-native-code-push": "^5.6.1",
    "react-native-fast-image": "^7.0.2",
    "react-native-fbsdk": "git+https://github.com/facebook/react-native-fbsdk.git",
    "react-native-gesture-handler": "^1.3.0",
    "react-native-google-signin": "^2.0.0",
    "react-native-reanimated": "^1.1.0",
    "react-native-screens": "^1.0.0-alpha.23",
    "react-native-sentry": "^0.43.2",
    "react-native-webview": "^5.12.1",
    "react-navigation": "^3.11.1",
    "react-redux": "^7.1.0",
    "redux": "^4.0.4",
    "redux-thunk": "^2.3.0",
    "styled-components": "^4.3.2",
    "urbanairship-react-native": "^3.1.1",
    "yup": "^0.27.0"
  }

@fontesrp
Copy link

fontesrp commented Sep 9, 2019

If anyone else has this issue, I solved it by editing my MainActivity so it does not try to re-open the app's saved state:

public class MainActivity extends ReactActivity {
  @Override
  protected void onCreate(Bundle savedInstance) {
    // super.onCreate(savedInstance);
    super.onCreate(null);
  }
}

@douglasjunior
Copy link

Similar problem here reported by the Google Play Store:

Samsung Galaxy J7 Prime (on7xelte), Android 8.1

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2974)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3059)
  at android.app.ActivityThread.-wrap11 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1724)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:7000)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:441)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1408)
Caused by: androidx.fragment.app.Fragment$InstantiationException: 
  at androidx.fragment.app.Fragment.instantiate (Fragment.java:465)
  at androidx.fragment.app.FragmentContainer.instantiate (FragmentContainer.java:50)
  at androidx.fragment.app.FragmentState.instantiate (FragmentState.java:80)
  at androidx.fragment.app.FragmentManagerImpl.restoreAllState (FragmentManager.java:3109)
  at androidx.fragment.app.FragmentController.restoreAllState (FragmentController.java:158)
  at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:344)
  at androidx.appcompat.app.AppCompatActivity.onCreate (AppCompatActivity.java:85)
  at com.facebook.react.ReactActivity.onCreate (ReactActivity.java:51)
  at app.klist.mobileapp.MainActivity.onCreate (MainActivity.java:17)
  at android.app.Activity.performCreate (Activity.java:7258)
  at android.app.Activity.performCreate (Activity.java:7249)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1222)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2927)
Caused by: java.lang.reflect.InvocationTargetException: 
  at java.lang.reflect.Constructor.newInstance0 (Native Method)
  at java.lang.reflect.Constructor.newInstance (Constructor.java:334)
  at androidx.fragment.app.Fragment.instantiate (Fragment.java:443)
Caused by: java.lang.IllegalStateException: 
  at com.swmansion.rnscreens.Screen$ScreenFragment.<init> (Screen.java:23)

@vikjovanov
Copy link

@douglasjunior I have the exact same error from the Google Play Console, how did you solve this problem?

@douglasjunior
Copy link

Hi @vikjovanov, sorry, I removed the react-native-screens from the projects until it became stable, I had a lot of crash problems so we decided not to insist for now.

@vikjovanov
Copy link

@douglasjunior Thank you for your answer, and do you feel a significant difference in performance or not?

@douglasjunior
Copy link

douglasjunior commented Feb 19, 2020

I always used "react-navigation" without this lib, I was just experimenting.

The only difference you will have would be in apps that open a very large stack of screens.

In the case of these apps you will have a RAM savings using "react-native-screens".

@vikjovanov
Copy link

@douglasjunior Ok ok ! Thanks a lot for your feedback, I'll think about it because I also have a lot of problems on Android with react-native-screens!

@kmagiera
Copy link
Member

I believe this issue should be resolved as of the latest version 2.0.0-beta.8. I can't tell for 100% because there was no repro scenario we could use to verify but fixes for few similar crashes have been applied since alpha.22. If you can still repro this on 2.0.0-beta.8 please provide a small repro app and start a new issue or comment here and I'll reopen.

@douglasjunior
Copy link

@kmagiera Did "react-native-screens" have any versions requirements for "react-native-reanimated" or "react-native-gesture-handler"?

@kmagiera
Copy link
Member

what do you mean by "version requirement". Those three packages are all disjoint and not directly depend on each other. There are some libraries that depend on some combination of these three but out of the box they are not coupled

@rinpatva14
Copy link

Hi @kmagiera,
Facing same issue still in version - 2.3.0.

Issue.- com.facebook.react.ReactActivity.onCreate.
Crash when app launch - Many live app user reported this issue.

@fontesrp
Copy link

fontesrp commented Mar 30, 2020

I'm facing the issue again too (using 2.4.0). I don't believe a repo with a reproducible project is necessary in this case, as it's very simple to reproduce and most of the steps are done in the device, rather than in the code:

On a physical device, go to Developer Options and enable the "Don't keep activities" option; then run your project (make sure you're calling enableScreens()); press the home button to put it in the background and then re-open it.

The workaround I provided here still works

@rahulje9
Copy link

I was on version 2.0.0-alpha.32 and this happened. so I upgraded all the packages and now I'm on 2.9.0 and still, this is happening to me.

@anishtr4
Copy link

If anyone else has this issue, I solved it by editing my MainActivity so it does not try to re-open the app's saved state:

public class MainActivity extends ReactActivity {
  @Override
  protected void onCreate(Bundle savedInstance) {
    // super.onCreate(savedInstance);
    super.onCreate(null);
  }
}

This works for me but will this make any impact on the app ? removing the " // enableScreens();" also does the job, But I am not sure which one will be better and right solution.

@grantgeorge
Copy link

grantgeorge commented Aug 28, 2020

If anyone else has this issue, I solved it by editing my MainActivity so it does not try to re-open the app's saved state:

public class MainActivity extends ReactActivity {
  @Override
  protected void onCreate(Bundle savedInstance) {
    // super.onCreate(savedInstance);
    super.onCreate(null);
  }
}

UPDATE I may have jumped the gun here... was debugging with the Don't keep activities developer option enabled and that seems to be the cause of the issue I described

As implied, this disables loading the saved application state when re-opening the app after backgrounding it. Be warned that this can break application functionality. This includes the navigation stack which will now be wiped-out.
In our case, this has an unacceptable side-effect of not being able to use the document picker to upload pictures and other media as it would return them to the incorrect state after picking media.

@anishtr4
Copy link

@ALL In my case the app was crashing when I am rotating the screen. I had fixed this issue without compromising/disabling neither the app state nor the "enableScreens()". I just had to update my activity in manifest file like below.

  <activity
    android:name=".MainActivity"
    android:label="@string/app_name" 
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize" // add this line

Note: Keep in mind that this ill prevent your app from rerendering on screen orientation. But it works.

@qoyyima22
Copy link

Hi, I've tried to add these lines of code in MainActivity.java, and it works with developer option enabled-disabled scenario for me. In my case, after restoring from background and activities being kept it will preserve the state, otherwise, if the activities not kept it will show the splash screen again.

@Override protected void onDestroy() { super.onDestroy(); finish(); }

I don't know if it's nonsense, but it worked for me. Hope it helps someone.

@kscc25
Copy link

kscc25 commented May 29, 2021

I have the same issue after upgrade to 3.3.0. Could someone reopen this issue?

here the full stack trace:

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3271)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3410)
  at android.app.ActivityThread.handleRelaunchActivityInner (ActivityThread.java:5280)
  at android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:5188)
  at android.app.servertransaction.ActivityRelaunchItem.execute (ActivityRelaunchItem.java:69)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2017)
  at android.os.Handler.dispatchMessage (Handler.java:107)
  at android.os.Looper.loop (Looper.java:214)
  at android.app.ActivityThread.main (ActivityThread.java:7397)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:492)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:935)
Caused by: androidx.fragment.app.Fragment$InstantiationException: 
  at androidx.fragment.app.Fragment.instantiate (Fragment.java:566)
  at androidx.fragment.app.FragmentContainer.instantiate (FragmentContainer.java:57)
  at androidx.fragment.app.FragmentManager$3.instantiate (FragmentManager.java:390)
  at androidx.fragment.app.FragmentStateManager.<init> (FragmentStateManager.java:74)
  at androidx.fragment.app.FragmentManager.restoreSaveState (FragmentManager.java:2454)
  at androidx.fragment.app.FragmentController.restoreSaveState (FragmentController.java:196)
  at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:287)
  at androidx.appcompat.app.AppCompatActivity.onCreate (AppCompatActivity.java:106)
  at com.facebook.react.ReactActivity.onCreate (ReactActivity.java:44)
  at android.app.Activity.performCreate (Activity.java:7825)
  at android.app.Activity.performCreate (Activity.java:7814)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1307)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3246)
Caused by: java.lang.reflect.InvocationTargetException: 
  at java.lang.reflect.Constructor.newInstance0 (Native Method)
  at java.lang.reflect.Constructor.newInstance (Constructor.java:343)
  at androidx.fragment.app.Fragment.instantiate (Fragment.java:548)
Caused by: java.lang.IllegalStateException: 
  at com.swmansion.rnscreens.ScreenFragment.<init> (ScreenFragment.java:46)

@shwetalii
Copy link

If anyone else has this issue, I solved it by editing my MainActivity so it does not try to re-open the app's saved state:

public class MainActivity extends ReactActivity {
  @Override
  protected void onCreate(Bundle savedInstance) {
    // super.onCreate(savedInstance);
    super.onCreate(null);
  }
}

UPDATE I may have jumped the gun here... was debugging with the Don't keep activities developer option enabled and that seems to be the cause of the issue I described

As implied, this disables loading the saved application state when re-opening the app after backgrounding it. Be warned that this can break application functionality. This includes the navigation stack which will now be wiped-out.
In our case, this has an unacceptable side-effect of not being able to use the document picker to upload pictures and other media as it would return them to the incorrect state after picking media.

This fix resolves the crash but as the activity is crashed in background, the app looses its state and gets stuck at the first screen. Navigation to further screens is blocked with this fix.

@mohamadnavabi
Copy link

This bug was fixed for me. When I downgraded to react-native-screens@^2.15.0

@SudoPlz
Copy link

SudoPlz commented Sep 1, 2021

@kmagiera Still seeing this crash in react-native-screens@3.6.0

Can we re-open that issue?

The stack trace is:

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3827)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:4003)
  at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:85)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2317)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:246)
  at android.app.ActivityThread.main (ActivityThread.java:8595)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:602)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1130)
Caused by: androidx.fragment.app.Fragment$InstantiationException: 
  at androidx.fragment.app.Fragment.instantiate (Fragment.java:631)
  at androidx.fragment.app.FragmentContainer.instantiate (FragmentContainer.java:57)
  at androidx.fragment.app.FragmentManager$3.instantiate (FragmentManager.java:483)
  at androidx.fragment.app.FragmentStateManager.<init> (FragmentStateManager.java:85)
  at androidx.fragment.app.FragmentManager.restoreSaveState (FragmentManager.java:2728)
  at androidx.fragment.app.FragmentController.restoreSaveState (FragmentController.java:198)
  at androidx.fragment.app.FragmentActivity$2.onContextAvailable (FragmentActivity.java:149)
  at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable (ContextAwareHelper.java:99)
  at androidx.activity.ComponentActivity.onCreate (ComponentActivity.java:322)
  at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:273)
  at com.facebook.react.ReactActivity.onCreate (ReactActivity.java:44)
  at com.acuityscheduling.client.android.MainActivity.onCreate (MainActivity.java:33)
  at android.app.Activity.performCreate (Activity.java:8207)
  at android.app.Activity.performCreate (Activity.java:8191)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1309)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3800)
Caused by: java.lang.reflect.InvocationTargetException: 
  at java.lang.reflect.Constructor.newInstance0 (Native Method)
  at java.lang.reflect.Constructor.newInstance (Constructor.java:343)
  at androidx.fragment.app.Fragment.instantiate (Fragment.java:613)
Caused by: java.lang.IllegalStateException: 
  at com.swmansion.rnscreens.ScreenFragment.<init> (ScreenFragment.kt:34)

@0b3r
Copy link

0b3r commented Sep 6, 2021

Same issue.

The stack trace is:

ava.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3449)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3601)
  at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:85)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2066)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:223)
  at android.app.ActivityThread.main (ActivityThread.java:7656)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:592)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:947)
Caused by: androidx.fragment.app.Fragment$InstantiationException: 
  at androidx.fragment.app.Fragment.instantiate (Fragment.java:566)
  at androidx.fragment.app.FragmentContainer.instantiate (FragmentContainer.java:57)
  at androidx.fragment.app.FragmentManager$3.instantiate (FragmentManager.java:390)
  at androidx.fragment.app.FragmentStateManager.<init> (FragmentStateManager.java:74)
  at androidx.fragment.app.FragmentManager.restoreSaveState (FragmentManager.java:2454)
  at androidx.fragment.app.FragmentController.restoreSaveState (FragmentController.java:196)
  at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:287)
  at androidx.appcompat.app.AppCompatActivity.onCreate (AppCompatActivity.java:115)
  at com.facebook.react.ReactActivity.onCreate (ReactActivity.java:44)
  at com.gighoundwork.MainActivity.onCreate (MainActivity.java:27)
  at android.app.Activity.performCreate (Activity.java:8000)
  at android.app.Activity.performCreate (Activity.java:7984)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1309)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3422)
Caused by: java.lang.reflect.InvocationTargetException: 
  at java.lang.reflect.Constructor.newInstance0 (Native Method)
  at java.lang.reflect.Constructor.newInstance (Constructor.java:343)
  at androidx.fragment.app.Fragment.instantiate (Fragment.java:548)
Caused by: java.lang.IllegalStateException: 
  at com.swmansion.rnscreens.ScreenFragment.<init> (ScreenFragment.java:44)

@shwetalii
Copy link

If anyone else has this issue, I solved it by editing my MainActivity so it does not try to re-open the app's saved state:

public class MainActivity extends ReactActivity {
  @Override
  protected void onCreate(Bundle savedInstance) {
    // super.onCreate(savedInstance);
    super.onCreate(null);
  }
}

UPDATE I may have jumped the gun here... was debugging with the Don't keep activities developer option enabled and that seems to be the cause of the issue I described

As implied, this disables loading the saved application state when re-opening the app after backgrounding it. Be warned that this can break application functionality. This includes the navigation stack which will now be wiped-out.
In our case, this has an unacceptable side-effect of not being able to use the document picker to upload pictures and other media as it would return them to the incorrect state after picking media.

This fix resolves the crash but as the activity is crashed in background, the app looses its state and gets stuck at the first screen. Navigation to further screens is blocked with this fix.

Hi,
I was playing around this issue ...and by chance I happened to change my laptop. We required to install react-native-screens ONLY to suffice its peer dependency for react-navigation. Previously when I had this issue reproducible in old machine, I had node version of '14.8.0', where I had to manually install react-native-screens by keeping its entry in package.json. But after changing my machine, when we tested using the latest node version i.e. '16.5.0' and we noticed that this version of node automatically installs all peer dependencies without having need to put them manually in package.json. Apparently this crash is fixed after moving to latest node version along with the change mentioned in above comment(sending null to onCreate). So as a fix, we removed react-native-screens from package.json and updated node to the latest version. So now, even with setting 'Don't keep Activities'...This crash is not reproducible for us. We are targeting to verify this on production in our next release though.

@shwetalii
Copy link

If anyone else has this issue, I solved it by editing my MainActivity so it does not try to re-open the app's saved state:

public class MainActivity extends ReactActivity {
  @Override
  protected void onCreate(Bundle savedInstance) {
    // super.onCreate(savedInstance);
    super.onCreate(null);
  }
}

UPDATE I may have jumped the gun here... was debugging with the Don't keep activities developer option enabled and that seems to be the cause of the issue I described

As implied, this disables loading the saved application state when re-opening the app after backgrounding it. Be warned that this can break application functionality. This includes the navigation stack which will now be wiped-out.
In our case, this has an unacceptable side-effect of not being able to use the document picker to upload pictures and other media as it would return them to the incorrect state after picking media.

This fix resolves the crash but as the activity is crashed in background, the app looses its state and gets stuck at the first screen. Navigation to further screens is blocked with this fix.

Hi, I was playing around this issue ...and by chance I happened to change my laptop. We required to install react-native-screens ONLY to suffice its peer dependency for react-navigation. Previously when I had this issue reproducible in old machine, I had node version of '14.8.0', where I had to manually install react-native-screens by keeping its entry in package.json. But after changing my machine, when we tested using the latest node version i.e. '16.5.0' and we noticed that this version of node automatically installs all peer dependencies without having need to put them manually in package.json. Apparently this crash is fixed after moving to latest node version along with the change mentioned in above comment(sending null to onCreate). So as a fix, we removed react-native-screens from package.json and updated node to the latest version. So now, even with setting 'Don't keep Activities'...This crash is not reproducible for us. We are targeting to verify this on production in our next release though.

Hi,
This solution has worked for us and there is no related crash event anymore on production as well.

@khaled-hbaieb
Copy link

Hi,
did anyone find a solution to this problem?
I am still having this problem in production.

@Abandonedengineer
Copy link

Hi,
did anyone find a solution to this problem?
I am still having this problem in production.

+1

@omar-bear
Copy link

omar-bear commented Nov 2, 2021

still not working for me ...
Google play report

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2977)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3114)
  at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:78)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:113)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:71)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1859)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:201)
  at android.app.ActivityThread.main (ActivityThread.java:6831)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:547)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:927)
Caused by: androidx.fragment.app.Fragment$InstantiationException: 
  at androidx.fragment.app.Fragment.instantiate (Fragment.java:566)
  at androidx.fragment.app.FragmentContainer.instantiate (FragmentContainer.java:57)
  at androidx.fragment.app.FragmentManager$3.instantiate (FragmentManager.java:390)
  at androidx.fragment.app.FragmentStateManager.<init> (FragmentStateManager.java:74)
  at androidx.fragment.app.FragmentManager.restoreSaveState (FragmentManager.java:2454)
  at androidx.fragment.app.FragmentController.restoreSaveState (FragmentController.java:196)
  at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:287)
  at androidx.appcompat.app.AppCompatActivity.onCreate (AppCompatActivity.java:106)
  at com.facebook.react.ReactActivity.onCreate (ReactActivity.java:44)
  at android.app.Activity.performCreate (Activity.java:7224)
  at android.app.Activity.performCreate (Activity.java:7213)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1271)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2957)
Caused by: java.lang.reflect.InvocationTargetException: 
  at java.lang.reflect.Constructor.newInstance0 (Native Method)
  at java.lang.reflect.Constructor.newInstance (Constructor.java:343)
  at androidx.fragment.app.Fragment.instantiate (Fragment.java:548)
Caused by: java.lang.IllegalStateException: 
  at com.swmansion.rnscreens.ScreenFragment.<init> (ScreenFragment.java:46)

@dev-dominionsoftware
Copy link

dev-dominionsoftware commented Nov 3, 2021

I'm facing with the same problem.

"react-native": "0.64.2"
"react-native-screens": "3.3.0"

When I open app in split view and resize window, then crash happen:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.northmill.rebilla/com.northmill.rebilla.base.activity.RebillaMainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenFragment: calling Fragment constructor caused an exception
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3835)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4011)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2325)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8633)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

@kacperkapusciak
Copy link
Member

@omar-bear @mksoftware101 writing "same" on a 2-year-old issue isn't very helpful.

Make sure you follow installation steps from README. If that doesn't solve the problem please open a new issue with proper description and reproduction.

Cheers

@software-mansion software-mansion locked as spam and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests