1

I'm facing some crashes in my application with the following stacktrace:

Fatal Exception: java.lang.IllegalStateException: Activity has been destroyed
   at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1560)
   at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:696)
   at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:667)
   at ....activities.MyActivity.replaceContentFragment(MyActivity.java:293)

This only happens for activities where I load content asynchronously from web and the replace the according fragment. I don't understand how the activity can be gone as the user cannot change fragments/activities while loading. I guess it must have to do with leaving/starting the app while loading (although I may be wrong about this).

My activities do have launchMode = singletask, maybe that's related as well.

The crashes appear on Android 6.0.1, but maybe that's due to the fact that the users mostly have that version...

swalkner
  • 16,679
  • 31
  • 123
  • 210
  • If the user triggers a configuration change (e.g. orientation change) while your app is loading content the activity will be destroyed and recreated instantly. If the user gets a whatsapp notification and decides to watch the video which was shared by a friend (so the device may be running low on memory) the activity may be destroyed and recreated as soon as the user returns. So I think maybe you try to access the "old" activity instance. – Bö macht Blau Nov 10 '16 at 08:15
  • orientation change doesn't trigger a configuration change in my app - I just tried it and the activity didn't get destroyed... And I do get the crash also on devices with > 20% RAM free according to Crashlytics... – swalkner Nov 10 '16 at 08:20
  • Did you set `android:configChanges="orientation"` in the Manifest for this activity? – Bö macht Blau Nov 10 '16 at 08:26
  • have you used tablayout or viewpager – Pavya Nov 10 '16 at 08:32
  • I suppose, you can find the solution here: http://stackoverflow.com/questions/15207305/getting-the-error-java-lang-illegalstateexception-activity-has-been-destroyed – Hetfieldan24 Nov 10 '16 at 08:33
  • @0X0nosugar I use `android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"` @Hetfieldan24 but there it says that it's fixed with support version 24 which I'm using – swalkner Nov 10 '16 at 08:37
  • 1
    That's a long list :) Other possible source of config change (uiMode): user "places the device into a desk/car dock or when the night mode changes" My guess is your code refers to the destroyed activity instance, so you have to make sure the new activity instance will be accessed. Hard to tell what to do exactly without code. – Bö macht Blau Nov 10 '16 at 08:47

0 Answers0