In my Android app onSaveInstanceState()
is always being called when app goes in the background. My understanding was that onSaveInstanceState()
will be called when OS kills the app. Taking this into account I designed some logic. But, during implementation I noticed this strange behaviour.
Is there a way to differentiate onSaveInstanceState()
that is being called after OS kills the app, and when it's being called on normal pause?
According to the documentation:
This method is called before an activity may be killed so that when it comes back some time in the future it can restore its state.
In other words, the method is not called immediately before the activity is killed by the OS. It is called when the activity goes into the background and there is a chance that it might later be restored. Saving the state immediately before the activity goes into the background gives the system more flexibility in how it kills applications... once it makes the decision that an application is killed, it can do so immediately (it doesn't have to worry about calling the application's onSaveInstanceState()
method before it can do so).