androidactivity-lifecycleonsaveinstancestateonrestoreinstancestate

What happens to the Activity lifecycle after an app update?


Suppose this scenario. You have an app where you fill a form in one activity. The activity uses onRestoreInstanceState and onSaveInstanceState to save the responses of the form. If a user is filling the form with app version 1, and then the PlayStore automatically updates and installs the app to version 2 before he finishes, what version was the form completed on?

Same question but supposing the user forces the update?

Thanks


Solution

  • The app update is a process involving the apk currently stored on your device and the updated apk from PlayStore. To apply the update, the system will kill your application.

    Originally(before API21), the bundle containing the InstanceState was valid only if the app was opened, but after API21 you can set the persistableMode true, so your bundle will survive to process kill and will be available in your onCreate(Bundle, PersistableBundle) method as second parameter.