简体   繁体   English

如果App进程终止,捆绑包如何发送到onCreate?

[英]How is bundle sent to onCreate if App process killed?

In the Activity Lifecycle diagram there's an arrow from 'onStop' to 'App process killed' to 'onCreate'. 在“活动生命周期”图中,从“ onStop”到“已终止应用程序进程”再到“ onCreate”有一个箭头。 I've always wondered, and now I'm going to give a small talk on fragments; 我一直想知道,现在我将对片段进行一些简短的讨论。 How is it possible for onCreate to receive the bundle from onStop if the whole app process is destroyed? 如果整个应用程序进程被销毁,onCreate如何从onStop接收捆绑软件? Does the system keep track of killed apps and their activity bundles? 系统是否跟踪已终止的应用程序及其活动包? I think that would be how it would do it because at that point the killed application would have zero memory allocated to it. 我认为这将是这样做的方法,因为到那时,被终止的应用程序将被分配零内存。

Also, from the last paragraph on the page Managing the Activity Lifecycle>Starting an Activity, "The system calls onDestroy() after it has already called onPause() and onStop() in all situations except one:...' And that one situation isn't stated as being low on memory. This makes me think that the arrow should never go from onStop to onCreate because of 'Apps with higher priority need memory'. Is this a typo or am I reading it wrong? I assume I'm reading it wrong because of the 'Killable?' 另外,在“管理活动生命周期”>“启动活动”页面的最后一段中,“系统在所有情况下都已经调用过onPause()和onStop()之后调用了onDestroy()。这种情况并不是说内存不足,这使我认为箭头永远不应该从onStop转到onCreate,因为“具有更高优先级的应用需要内存”,这是拼写错误还是我读错了吗? '因为“可杀死的”而读错了吗? column in 'in general the movement through an activity's lifecycle looks like this:' chart. “通常情况下,活动生命周期中的移动如下:”图表。

One of these has to be wrong either the arrow in the activity lifecycle chart or the "The system calls onDestroy() after it has already called onPause() and onStop() in all situations except one:..." statement. 其中之一必须是错误的,要么是活动生命周期图中的箭头,要么是“在所有情况下,系统已经调用过onPause()和onStop()之后,系统调用onDestroy(),除了一个:...”语句。 Hopefully I'm reading out of context. 希望我在上下文之外阅读。

How is it possible for onCreate to receive the bundle from onStop if the whole app process is destroyed? 如果整个应用程序进程被销毁,onCreate如何从onStop接收捆绑软件?

It doesn't "receive the bundle from onStop", insofar as onStop() has nothing to do with a Bundle . 只要onStop()Bundle无关,它就不会“从onStop接收捆绑”。 The Bundle delivered to onCreate() and onRestoreInstanceState() contains the data put in an earlier Bundle by onSaveInstanceState() . Bundle传递到onCreate()onRestoreInstanceState()包含把在前面的数据Bundle通过onSaveInstanceState() The content of that Bundle is passed across process boundaries to a core OS process that manages the state of outstanding activities and their tasks. Bundle的内容跨进程边界传递到核心OS进程,该进程管理未完成活动及其任务的状态。 That content is passed back to the fresh process for your app if and when it is relevant. 如果相关的内容将被传递回您的应用程序的全新流程。

Does the system keep track of killed apps and their activity bundles? 系统是否跟踪已终止的应用程序及其活动包?

The OS keeps track of outstanding tasks. 操作系统跟踪未完成的任务。 For a while (~30 minutes since last use), it keeps track of the instance state Bundle for the activities on the task. 一段时间(自上次使用以来约30分钟),它会跟踪任务活动的实例状态Bundle

The system calls onDestroy() after it has already called onPause() and onStop() in all situations except one 系统在除一种情况以外的所有情况下都已经调用过onPause()和onStop()之后调用onDestroy()

There is more than one situation in which onDestroy() is not called. 在不调用onDestroy()情况下,有不止一种情况。 Terminating the process due to low memory conditions may or may not result in onDestroy() being called, depending on the urgency of the need for system RAM. 由于内存不足的情况而终止该过程可能会或可能不会导致调用onDestroy() ,具体取决于对系统RAM的迫切需求。

It is very possible for onCreate to be called after onStop(). onCreate很可能在onStop()之后被调用。 You pass bundles using onSaveInstanceState() which is called anytime the activity or fragment pauses or stops. 您使用onSaveInstanceState()传递捆绑包,只要活动或片段暂停或停止,就会调用它。 Say you have an activity and press home. 假设您有活动,然后按回家。 OnStop and onSaveInstanceState are both called. OnStop和onSaveInstanceState都被调用。 In onSaveInstanceState you save your bundle to save the state of the app. 在onSaveInstanceState中,您可以保存捆绑包以保存应用程序的状态。 The app is then killed because it was in the background for too long. 该应用随后在后台停留了太长时间,因此被杀死。 Then when you open the app back up the bundle from onSaveInstanceState is passed to oncreate in the SavedInstanceState parameter when ever it gets recreated. 然后,当您打开应用程序时,一旦重新创建,则将束从onSaveInstanceState传递到SavedInstanceState参数中的oncreate。 See the official docs for more https://developer.android.com/training/basics/activity-lifecycle/recreating.html 有关更多信息,请参阅官方文档https://developer.android.com/training/basics/activity-lifecycle/recreating.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM