Last active
August 29, 2015 14:27
-
-
Save noaht11/d853b045feb83f25041b to your computer and use it in GitHub Desktop.
Restoring very simple state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final String STATE_COUNTER = "counter"; | |
private TextView mCounterTextView; | |
private int mCounter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
... | |
// If we have a saved state then we can restore it now | |
if (savedInstanceState != null) { | |
mCounter = savedInstanceState.getInt(STATE_COUNTER, 0); | |
} | |
// Display the value of the counter | |
mCounterTextView = (TextView) findViewById(R.id.counter_text); | |
mCounterTextView.setText(Integer.toString(mCounter)); | |
... | |
} | |
@Override | |
protected void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
outState.putInt(STATE_COUNTER, mCounter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment