I\'m using the recommended approach for Up Navigation and my code looks like this:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switc
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);