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 crashes when resuming from background AND navigation occurs using fragments.

See original GitHub issue

We 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:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
rodperottonicommented, Mar 23, 2021

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.

3reactions
amutschBBYcommented, Mar 22, 2021

@WoLewicki The testing is continuing to go good on this PR, I’ll be getting that PR setup this week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android fragments activity crashes
I'm trying to use fragments in a layout. My Android app targets 4.0.0 and newer, so I'm not using the v4 support library,...
Read more >
Unexpected App Crashes on Android and How to Deal with ...
When the user navigates back to the app from the background, if the app process was killed, the app would restart from the...
Read more >
Crashes
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >
Activity with fragment crashes when coming back from ... - MSDN
What i understood from my research is that the activity and everything else gets destroyed and ones the app is opened again, everything...
Read more >
One Activity to Rule Them All
Reducing crashes and increasing engagement with Etsy's Android app through ... But what happens when we expect an Activity to host multiple Fragments, ......
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