[英]What is holding my activity's state once my application process has been killed?
I've been testing the behavior of my program by running a memory-eating application that forces my application to be killed.我一直在通过运行一个强制终止我的应用程序的内存占用应用程序来测试我的程序的行为。 After reading the answers to Where is the bundle of onSaveInstanceState saved?
阅读了onSaveInstanceState 的包在哪里保存的答案后? , I'm confused about some of the results I'm seeing.
,我对我看到的一些结果感到困惑。
Both answers given in that link imply that individual activities, not applications, are destroyed when memory needs to be reclaimed.该链接中给出的两个答案都暗示,当需要回收内存时,会销毁单个活动,而不是应用程序。 But according to http://developer.android.com/guide/components/processes-and-threads.html , processes - not individual activities - are killed.
但是根据http://developer.android.com/guide/components/processes-and-threads.html ,进程 - 而不是单个活动 - 被杀死。 And since all components usually run in the same process, I would expect the entire application to be killed in low memory situations.
而且由于所有组件通常都在同一进程中运行,我希望整个应用程序在内存不足的情况下会被杀死。 My testing is consistent with the Android documentation in that I no longer see the process running when I run my memory eating app.
我的测试与 Android 文档一致,因为当我运行我的内存消耗应用程序时,我不再看到进程正在运行。
So if the entire process is killed, am I correct in assuming that the answers given in that question are incorrect?因此,如果整个过程被终止,我是否正确地假设该问题中给出的答案不正确? But if so, what's keeping my Bundle around when I resume my application if the process was killed?
但是如果是这样,如果进程被终止,当我恢复我的应用程序时,我的 Bundle 是什么? Is it really guaranteed to never be written to disk?
真的保证永远不会写入磁盘吗?
Both answers given in that link imply that individual activities, not applications, are destroyed when memory needs to be reclaimed.
该链接中给出的两个答案都暗示,当需要回收内存时,会销毁单个活动,而不是应用程序。
That is incorrect, though I was confused on this point for a long time myself.这是不正确的,尽管我自己在这一点上困惑了很长时间。
IMHO, at most one of the three answers on that question "imply that individual activities, not applications, are destroyed when memory needs to be reclaimed".恕我直言,该问题的三个答案中最多有一个“意味着当需要回收内存时,单个活动而不是应用程序将被销毁”。
But if so, what's keeping my Bundle around when I resume my application if the process was killed?
但是如果是这样,如果进程被终止,当我恢复我的应用程序时,我的 Bundle 是什么?
Sometimes, nothing is "keeping [your] Bundle around".有时,没有什么是“保留 [您的] 捆绑包”。 Other times, a process central to the OS is "keeping [your] Bundle around".
其他时候,操作系统的核心进程是“保留 [您的] 捆绑包”。
Is it really guaranteed to never be written to disk?
真的保证永远不会写入磁盘吗?
Is not "guaranteed", insofar as it is not documented whether or not it is written to disk.不是“保证”,因为它没有记录是否写入磁盘。 If it is written to disk, it will be done so by an OS process (not yours), and the file should be unreadable by other processes.
如果它被写入磁盘,它将由一个操作系统进程(不是你的)完成,并且该文件应该无法被其他进程读取。
As today the documentation says that saved instance state is serialized to disk.正如今天文档所说,保存的实例状态被序列化到磁盘。
https://developer.android.com/topic/libraries/architecture/saving-states#options_for_preserving_ui_state https://developer.android.com/topic/libraries/architecture/saving-states#options_for_preserving_ui_state
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.