gpt4 book ai didi

android - onSaveInstanceState() 不保证被调用

转载 作者:行者123 更新时间:2023-11-29 17:54:06 25 4
gpt4 key购买 nike

我已经阅读了android文档中的以下声明

Because onSaveInstanceState() is not guaranteed to be called, you should use it only to record the transient state of the activity (the state of the UI) — you should never use it to store persistent data

因为 onSaveInstanceState() 不能保证被调用。我们如何依靠它来保存数据?有什么特殊情况不会被调用吗?

最佳答案

因为nPn已经给了链接。阅读以下行

(引用:http://developer.android.com/reference/android/app/Activity.html)

One example of when onPause() and onStop() is called and not this method is when a user navigates back from activity B to activity A: there is no need to call onSaveInstanceState(Bundle) on B because that particular instance will never be restored, so the system avoids calling it. An example when onPause() is called and not onSaveInstanceState(Bundle) is when activity B is launched in front of activity A: the system may avoid calling onSaveInstanceState(Bundle) on activity A if it isn't killed during the lifetime of B since the state of the user interface of A will stay intact.

关于android - onSaveInstanceState() 不保证被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20815348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com