I'm a little bit confused about these two methods in Android.
From the documentation I understand that onSaveInstanceState()
should be called to store only temporary information, and onPause()
should be used to store any persistent data.
I was wondering why to call onSaveInstance()
at all, when onPause()
is called every time. Then I read in the Notepad tutorial:
"Note that
saveState()
must be called in bothonSaveInstanceState()
andonPause()
to ensure that the data is saved. This is because there is no guarantee thatonSaveInstanceState()
will be called and because when it is called, it is called beforeonPause()
."
There is no guarantee that onSaveInstanceState()
will be called because you can simply walk out of the activity using the back button.
But according to this if you don't save the persistent data inside both methods, the app might be killed while inside onSaveInstanceState()
.
So we need to save the persistent data in both methods actually, am I right?
But if this is true, isn't this too much of an overhead and maybe there should be some other additional flag to tell if the method is already called or something?
http://developer.android.com/resources/tutorials/notepad/notepad-ex3.html