简体   繁体   English

一旦我的应用程序进程被终止,我的活动状态是什么?

[英]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.

相关问题 我的Android APP进程已被终止,但仍在RunningTask中 - My Android APP's process has been killed, but still in RunningTask 重新创建活动后,该如何使用其恢复状态? - What do I use to restore my Activity's state when it has been recreated? 扫描我的二维码后转到下一个活动 - Moving to next activity once my QR Code has been scanned Android-在进程被杀死时恢复状态 - Android - restoring state when process has been killed Android:如何避免 Activity 被系统杀死,ActivityManager:处理我的 package 名称(pid 935)已死亡 - Android:How to Avoid Activity being killed by System,ActivityManager: Process my package name (pid 935) has died 如果某个进程在其活动仍然存在时被杀死了怎么办? - What if a process has been killed while its activities are still alive? Android在我的应用程序的流程上下文中调用其他应用程序的活动 - Android invoke activity of other application in my application's process context 如何知道我的应用程序何时被杀死? - How to know when my app has been killed? 检测我的活动何时被触及 - Detect when my activity has been touched 如何检查onCreate是否已杀死同一活动的先前android进程? - how to check in onCreate that the previous android process of the same activity has been killed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM