question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] Crash on killed app restore

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:32 (3 by maintainers)

github_iconTop GitHub Comments

28reactions
fontesrpcommented, 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);
  }
}
13reactions
fontesrpcommented, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do my apps keep crashing on Android, How to fix it
How to fix apps that keep crashing on Android · 1. Force stop the app · 2. Restart the device · 4. Reinstall...
Read more >
Android - restoring state when process has been killed
The problem is that when it tries to restore the activity even though I explicitly stated to start the launcher activity, it still...
Read more >
How to Fix Crashing Apps on an iPhone or Android?
I am a developer of iPhone/Android and my app keeps crashing on users ... Kill the App; Restart the Phone; Update the App;...
Read more >
Android process death — and the (big) implications for your app
By opening the app — the system will restore its' state and the user will not even notice that actually the process was...
Read more >
Top 6 Methods to Fix Apps Keep Crashing on Android
Part 2: Other Common Tips to Fix Android Apps Keep Closing Unexpectedly · 4. Clearing App Data. This solution is same as clearing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found