Android: onSaveInstanceState not being called from activity

后端 未结 5 1837
刺人心
刺人心 2020-12-01 06:04

I have an Activity A which calls Activity B. In Activity B, when i click on a button, finish() is called, which in turn calls onDestroy() of Activity B and returns to activi

5条回答
  •  醉梦人生
    2020-12-01 06:36

    Please notice that onRestoreInstanceState() is called when activity is recreated but only if:

    it was killed by the OS. "Such situation happen when:

    • orientation of the device changes (your activity is destroyed and recreated)
    • there is another activity in front of yours and at some point the OS kills your activity in order to free memory (for example). Next time when you start your activity onRestoreInstanceState() will be called."

    So if you are in your activity and you hit Back button on the device, your activity is finish()ed and next time you start your app it is started again (it sounds like re-created, isn't it?) but this time without saved state because you intentionally exited it when you hit Back button.

提交回复
热议问题