Android crashes when resuming from background AND navigation occurs using fragments.
See original GitHub issueWe are seeing the same error reported here and here and none of the solutions provided have worked for us. Our setup is slightly different though:
- We use navigation components since we have a single activity app.
- React native is loaded on a fragment using navigation components.
The use case that crashes the app 100% of the time is a deeplink IF we are previously on a react native screen. After some investigation we think the following occurs:
- The react native screen is loaded and then we background the app to open the email and click the a deeplink to the app.
- When clicking the link, react native resumes and react-native-screens starts rendering the views, which seem to use Fragments under the hood - creates Fragment transactions for this purpose.
- At the same time we are trying to navigate to handle the deeplink. Navigation components tries to use another Fragment transaction.
- The system crashes since there are multiple Fragment transactions not finished.
Libraries:
- “react-native-screens”: “2.10.1”
- “react-native”: “0.63.4”
- “react-navigation/native”: “5.7.2”
We have tried one thing: IF “react-native-screens”: “2.10.1” and we don’t force that version, ie change other dependencies to use that version, the resulting app has react-native-screens 2.10.1
AND 2.9.0
and the issue seems to be gone. However though this doesn’t sound like a very reliable thing to do.
The concerning lines are the following:
at com.swmansion.rnscreens.ScreenContainer.removeMyFragments(ScreenContainer.java:238) at com.swmansion.rnscreens.ScreenContainer.onDetachedFromWindow(ScreenContainer.java:250)
The stack trace we have is the following
java.lang.RuntimeException: Unable to resume activity {com.company.package.flavour.debug/com.company.MainActivity}: java.lang.IllegalStateException: FragmentManager is already executing transactions at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4219) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4251) at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2019) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7410) 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: java.lang.IllegalStateException: FragmentManager is already executing transactions at androidx.fragment.app.FragmentManager.ensureExecReady(FragmentManager.java:1790) at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1826) at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:303) at com.swmansion.rnscreens.ScreenContainer.removeMyFragments(ScreenContainer.java:238) at com.swmansion.rnscreens.ScreenContainer.onDetachedFromWindow(ScreenContainer.java:250) at android.view.View.dispatchDetachedFromWindow(View.java:19626) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3814) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3806) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3806) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3806) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3806) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3806) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3806) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3806) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3806) at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5431) at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5402) at android.view.ViewGroup.removeView(ViewGroup.java:5333) at androidx.fragment.app.FragmentContainerView.removeView(FragmentContainerView.java:317) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1262) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1368) at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1446) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1516) at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2019) at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1965) at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1861) at androidx.fragment.app.Fragment.performResume(Fragment.java:2745) at androidx.fragment.app.FragmentStateManager.resume(FragmentStateManager.java:373) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1211) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1368) at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1446) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1509) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2637) at androidx.fragment.app.FragmentManager.dispatchResume(FragmentManager.java:2601) at androidx.fragment.app.FragmentController.dispatchResume(FragmentController.java:269) at androidx.fragment.app.FragmentActivity.onResumeFragments(FragmentActivity.java:478) at androidx.fragment.app.FragmentActivity.onPostResume(FragmentActivity.java:467) at androidx.appcompat.app.AppCompatActivity.onPostResume(AppCompatActivity.java:204) at android.app.Activity.performResume(Activity.java:7964) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4209)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:17 (6 by maintainers)
Top GitHub Comments
I was able to consistently get this to happen by -> Opening an app that invokes
enableScreens()
-> Background the app -> Open the app’s settings and revoke a permission (e.g. location) -> Try to restore the app from the app drawer.The crash happens every single time.
@WoLewicki The testing is continuing to go good on this PR, I’ll be getting that PR setup this week.