android - onSaveInstanceState() 不保证被调用

标签 android

我已经阅读了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/

相关文章:

android - Volley 上下文中的 Kotlin 'it' 语法

android - 如何更快地接收通知,比如whatsapp

android - 如何在 exoplayer 中播放本地媒体文件的硬编码内容 uri

android - 动态替换 View 而不更改 Activity

android - 相当于 flutter 中的 "moveTaskToBack(true)"

android - ActivityManager 不保留 REAL_GET_TASKS 警告

android - 如何将超过 1 MB 的数据从 sqlite db 加载到 android 游标?

android - 如何在 webview 中单击 URL 时获取文件名

android - 我可以从内联函数更改实例的分配吗?

android - 移动客户端上的 Google Analytics