Skip to content Skip to sidebar Skip to footer

Android: Activities Destroyed Unexpectedly, Null Savedinstancestate

I am not going to list every reference I've read through before posting this, but I have extensively read similar questions on stackoverflow and all of the android developer docs o

Solution 1:

Although the question mentions Fragments, the problem is actually with up navigation.

The default implementation for up navigation doesn't work exactly as one would expect for standard activties. In particular, when the parent activity has launchMode="standard" (the default), pressing the up button will create a new instance of it, not return to the previous one.

There are two alternatives for solving this problem:

  1. Changing the launchMode of ImpulseActivity to singleTop in the Manifest.
  2. Overriding the home button action to launch the intent with the FLAG_ACTIVITY_CLEAR_TOP flag. For example, in EventActivity.onOptionsItemSelected():

    if (id == android.R.id.home)
    {
        Intent intent = NavUtils.getParentActivityIntent(this);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        NavUtils.navigateUpTo(this, intent);
        returntrue;
    }
    

Either of these will bring your old activity to the top of the stack.

Solution 2:

if your fragments have layout just like activity example mainlayout.xml you can use intent for open each fragment with same details and dont use onstop(); pack create intent and intent flags in the main fragment activity

Post a Comment for "Android: Activities Destroyed Unexpectedly, Null Savedinstancestate"