Reputation: 51
From an Android tutorial:
static final String STATE_SCORE = "playerScore";
static final String STATE_LEVEL = "playerLevel";
...
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save the user's current game state
savedInstanceState.putInt(STATE_SCORE, mCurrentScore);
savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel);
// Always call the superclass so it can save the view hierarchy state
super.onSaveInstanceState(savedInstanceState);
}
===================
Bundle savedInstanceState
<--- are we passing here a new Bundle object or an existing one?
Why are we calling super.onSaveInstanceState
in the end vs usually at the beginning?
sorry if they are dumb questions.
Upvotes: 0
Views: 61
Reputation: 104539
Same object, just with two additional key/value pairs added.
In this particular case, it does not likely matter if you call the parent method (onSaveInstanceState) before of after your code in the derived class implementation. It just matters that you DO call it somewhere in there so that the parent class (presumably Activity) can store its own state. Unless the code in the child method has any bearing on the behavior of the parent method, I usually call the parent method as the first line of such methods. I suppose it could matter if the parent class also stored identical key names called STATE_SCORE and STATE_LEVEL into the Bundle. Which ever putInt call that happened last would win.
Upvotes: 1