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.

FragmentManager has been destroyed

See original GitHub issue

Description

I can’t reproduce it, but it happened 1000 times in the last month in production. (Sentry and Google Console crash report)

This is the stack trace:

java.lang.IllegalStateException: FragmentManager has been destroyed at androidx.fragment.app.l.a at androidx.fragment.app.l.a at com.swmansion.rnscreens.g.onDetachedFromWindow at android.view.View.dispatchDetachedFromWindow(View.java:18679) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3886) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:5640) at android.view.ViewGroup.removeAllViews(ViewGroup.java:5586) at com.swmansion.rnscreens.d.onDetachedFromWindow at android.view.View.dispatchDetachedFromWindow(View.java:18679) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3886) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3878) at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5432) at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5403) at android.view.ViewGroup.removeView(ViewGroup.java:5334) at com.swmansion.rnscreens.d.removeView at androidx.fragment.app.l.a at androidx.fragment.app.l.j at androidx.fragment.app.l.i at androidx.fragment.app.l.a at androidx.fragment.app.l.b at androidx.fragment.app.l.c at androidx.fragment.app.l.c at androidx.fragment.app.l$d.run at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6944) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Screenshots

Steps To Reproduce

Can’t reproduce it, tried to kill activity and all that but didn’t reproduce… (I did put the onCreate(null) )

Snack or minimal code example

I’m using a nested navigator

The HomeStack is the native

function HomeNavigator() {
  return (
        <HomeStack.Navigator screenOptions={{ headerShown: false }}>
          <HomeStack.Screen
            options={{
              animationEnabled: false,
              stackAnimation: 'none',
            }}
            name={"Test"}
            component={TestScreen}
          />
          <HomeStack.Screen
            options={{
              animationEnabled: false,
              stackAnimation: 'none',
              drawerLockMode: 'locked-closed',
            }}
            name="Test2"
            component={Test2}
          />
        </HomeStack.Navigator>
  );
}

function DrawerNavigator({ currentScreen }) {
  return (
    <Drawer.Navigator
      drawerType="slide"
      backBehavior="none"
      drawerContent={props => {
        return <DrawerContent {...props} />;
      }}
    >
      <Drawer.Screen
        name={"Home"}
        component={HomeNavigator}
      />
    </Drawer.Navigator>
  );
} 

Package versions

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
diego-pairedcommented, Feb 8, 2021

Can you check if adding #805 fixes the crashes? From the stack trace it seems that the crash appears when you have a hierarchy of native-stack -> RN navigator with react-native-screens enabled (stack or bottom-tabs or drawer) -> native-stack. Then you change the screen in the top-most native-stack. I couldn’t reproduce the crash unfortunately, but I believe the change from #805 should address it correctly. If you will be able to reproduce it with this information, please do.

thanks, I’ll patch-package the change, submit it in our next release and let you know of the results.

0reactions
carlosvpintocommented, Sep 18, 2022

Tengo un error al intentar llamar un fragment por segunda vez, por favor ayudenme error ondestroy

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.IllegalStateException: FragmentManager has been ...
This happens when you get the FragmentManager from an Activity that was destroyed, usually if you do activity.
Read more >
Android: Fragment related pitfalls and how to avoid them
The FragmentManager can only recreate a Fragment if it's a public non-anonymous ... IllegalStateException: Activity has been destroyed”
Read more >
java.lang.illegalstateexception activity has been destroyed ...
If the fragment is removed, or if the FragmentManager is destroyed, the fragment's Lifecycle is moved into the DESTROYED state and sends the...
Read more >
FragmentManager.java - android Git repositories
+ view + " has already been destroyed. Nested fragments should always ". + "use the child FragmentManager."); } fm = fragment.getChildFragmentManager();. } ......
Read more >
[Solved]-Android 11 (only) FragmentManager crashes
Coding example for the question Android 11 (only) FragmentManager crashes - FragmentManager has been destroyed-kotlin.
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