I’m trying to teach myself some android programming and I’m unable to get my app to save and load a users progress.
Currently I initialise my variables level and score in my activity. Then call this from my onCreate method:
if (savedInstanceState != null) {
// Restore value of members from saved state
playersScore = savedInstanceState.getInt(STATE_SCORE);
level = savedInstanceState.getInt(STATE_LEVEL);
} else {
playersScore = 0;
level = 0;
}
and finally I have a method for saving a bundle:
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putInt(STATE_SCORE, playersScore);
savedInstanceState.putInt(STATE_LEVEL, level);
super.onSaveInstanceState(savedInstanceState);
}
For some reason my bundle wont save, any ideas on what I’m missing?
From the docs: