onPause()
should be used to save persistent
data and onSaveInstanceState(Bundle)
is typically used to save non-persistent
data.What does that mean?What is difference between persistent and non-persistent data?
Persistence data:
The data which is available after fully closing the application.
This type of data must be save into shared preference or database or internal or external memory
Non- persistence data:
The data which is not available after fully closing the application. we can say that non - persistence data mean volatile data that available during the execution of the application.
Persistent data is data which you want to be available even after you fully close and restart your app.
The three most common ways to safe this data localy is by using SharedPreferences, a local database or the file system (store data as a file).
Android Developers offers a guide for this: http://developer.android.com/training/basics/data-storage/index.html
onPause() should be used to save persistent data
Commit data that is going to be used throughout the life of the application. For example data inside your database or shared preferences.
onSaveInstanceState(Bundle) is typically used to save non-persistent data
Commit data that is specific to the current view session. For example keeping track of the current state of the views on screen.
© 2022 - 2024 — McMap. All rights reserved.