ActionBar up navigation recreates parent activity instead of onResume
Add the following to your parent activity in the manifest file
android:launchMode="singleTop"
regarding to this answer
The reason, the activities are recreated when using up-navigation is, that android uses standard launch mode for this, if you do not specify an other mode. That means
"The system always creates a new instance of the activity in the target task"
and thus the activity is recreated (see docu here).
A solution would be to either declare the launch mode of the MainActivity as
android:launchMode="singleTop"
in the AndroidManifest.xml
(should always work together with Intent.FLAG_ACTIVITY_CLEAR_TOP
)
or you could add FLAG_ACTIVITY_SINGLE_TOP
to your intent flags, to tell the activity, that it should not be recreated, if it is on the back stack, e.g.
Intent h = NavUtils.getParentActivityIntent(this);
h.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
NavUtils.navigateUpTo(this, h);
This code worked for me:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// This activity is NOT part of this app's task, so create a new task
// when navigating up, with a synthesized back stack.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(upIntent)
// Navigate up to the closest parent
.startActivities();
} else {
// This activity is part of this app's task, so simply
// navigate up to the logical parent activity.
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
NavUtils.navigateUpTo(this, upIntent);
}
return true;
No finish() invocation required.