How Do You Save Previous Activity Data In Kotlin So When You Reopen It, The Same Data Is Still There?
I'm making a quiz app and so far I've made the code for creating a question and answer in one activity which then takes you back to the main activity where a button with the text s
Solution 1:
you can use onSaveIntanceState method to save current activity data
@OverridepublicvoidonSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
// Save UI state changes to the savedInstanceState.// This bundle will be passed to onCreate if the process is// killed and restarted.
savedInstanceState.putString("activity", "my activity data");
// etc.
}
and for retrieve data when activity resumed you have to use savedInstanceState in onRestoreInstanceState method or in onCreate method
@OverridepublicvoidonRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// Restore UI state from the savedInstanceState.// This bundle has also been passed to onCreate.String myString = savedInstanceState.getBoolean("activity");
}
Post a Comment for "How Do You Save Previous Activity Data In Kotlin So When You Reopen It, The Same Data Is Still There?"