Reputation: 6881
I seem to have the opposite problem to everyone else. :)
My onSaveInstanceState is getting called whenever I navigate from one activity to the next. I checked in LogCat and it is definitely NOT killing the activity. Also, I see that the onRestoreInstanceState is not called when returning so it must have still been in memory.
I thought it was only called when freeing up memory or during orientation changes.
Upvotes: 3
Views: 836
Reputation: 2651
What about the doc saying;
"If called, this method will occur before onStop(). There are no guarantees about whether it will occur before or after onPause()."
Upvotes: 1
Reputation: 95578
Yes, onSaveInstanceState()
is called when the activity is paused. This is because once the activity is paused, Android can kill the process at any time time (without calling any other lifecycle methods). If the activity is resumed before the process is killed, Android realizes that it doesn't need to call onRestoreInstanceState()
so it doesn't make that call (this is an optimization).
Upvotes: 5