An app has 2 activities, A and B.
A has instance data that is saved
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("foo", 0);
}
and A has
int bar;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ...
if (savedInstanceState != null) {
bar = savedInstanceState.getInt("foo");
} else {
bar = -1;
}
}
to restore the data.
Activity B has the actionbar enabled and
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
// ...
}
to enable up navigation. Also A is listed as the parent activity of B in AndroidManifest.xml
.
When a user navigates from A to B onSaveInstanceState
is called and if they navigate back to A
using the back button activity A correctly restores it's saved information.
However when the user navigates from A to B onSaveInstanceState
is called and then up navigation is used to return to A the onCreate(Bundle savedInstanceState)
is passed null
even though information was saved.
How do I get up navigation to pass the the Bundle created in onSaveInstanceState
?