Issue
I'm trying to restore the previous state of my Activity
after pressing home and reopening the app so I'm saving what I need inside onSaveInstanceState
:
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_ACTIVE_VIEW_ID, mActiveViewId);
Log.v(TAG, this.toString() + " onSaveInstanceState");
}
that is called, but inside onCreate
the Bundle
is always null
.
This is OnCreate():
@Override
public void onCreate(Bundle inState) {
super.onCreate(inState);
setContentView(R.layout.main);
setMenuDrawer();
if (inState != null) {
int activeViewID = inState.getInt(STATE_ACTIVE_VIEW_ID);
View activeView = findViewById(activeViewID);
menuDrawer.setActiveView(activeView);
switchSelectedFragment(activeView);
Log.v(TAG, this.toString() + " onCreate " + inState.toString());
} else {
switchSelectedFragment(findViewById(R.id.homeView));
}
Log.v(TAG, this.toString() + " onCreate");
}
Solution
onSaveInstanceState
is called when the home button is pressed, but onCreate
will not be called again unless the Activity was destroyed (config change or memory reasons).
You should simply be able to hold onto the member variable, for dealing with onPause
/onResume
(which is what we're actually discussing). If you're not seeing the Fragment you'd expect (after returning from Home press), you have a different issue.
Answered By - Paul Burke
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.