Cris
Cris

Reputation: 12194

onSaveInstanceState when click back button in Android

I have an activity that is called at runtime in an Android App. When the user clicks the back button the Activity is destroyed and I overrode the onSaveInstanceState method to save outState to be retrieved in a second time but onSaveInstanceState is never called when the user clicks the back button.

Do you know why this happens?

Upvotes: 4

Views: 2019

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006799

onSaveInstanceState() is not supposed to be called when the user presses BACK.

It will be called when the user changes configuration (e.g., rotates the screen), if Android believes that the activity is at risk of being destroyed while still being reachable on the stack, and perhaps a few other cases.

Upvotes: 4

Related Questions