Skip to content

Instantly share code, notes, and snippets.

@Razeeman
Last active January 30, 2019 12:42
Show Gist options
  • Save Razeeman/afda1f7d13fda1ba3d8805192abfbe7e to your computer and use it in GitHub Desktop.
Save Razeeman/afda1f7d13fda1ba3d8805192abfbe7e to your computer and use it in GitHub Desktop.
Android, Java, onSaveInstanceState.
@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