Last active
January 30, 2019 12:42
-
-
Save Razeeman/afda1f7d13fda1ba3d8805192abfbe7e to your computer and use it in GitHub Desktop.
Android, Java, onSaveInstanceState.
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
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
/* | |
* If savedInstanceState is not null, that means our Activity is not being started for the | |
* first time. Even if the savedInstanceState is not null, it is smart to check if the | |
* bundle contains the key we are looking for. | |
*/ | |
if (savedInstanceState != null) { | |
if (savedInstanceState.containsKey(BUNDLE_KEY)) { | |
String textRestored = savedInstanceState.getString(BUNDLE_KEY); | |
} | |
} | |
} | |
@Override | |
protected void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
outState.putString(BUNDLE_KEY, textToSave); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment