什么是一个过程BroadcastReceiver的生命周期? [英] What's BroadcastReceiver lifecycle in a process?

查看:181
本文介绍了什么是一个过程BroadcastReceiver的生命周期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

读了一些问题之后/有关活动和流程生命周期的答案。我想我了解有关的活动和流程的生命周期的细节。但我感到困惑,这些观察员类似的BroadcastReceiver / ContentObserver与流程的生命周期。

After reading some questions/answers about activity and process lifecycle. I suppose I understand the details about activity and process lifecycle. But I'm confused about these Observers like BroadcastReceiver/ContentObserver with process lifecycle .

我想知道的是,当我注册一个BroadcastReciver(即一个BroadcastReceiver监听短信接收意图),如果其注册的BroadcastReceiver的过程中已经存在,当系统调用的BroadcastReceiver,

What I want to know is, when I register a BroadcastReciver (i.e, a BroadcastReceiver listen on SMS receive intent),if the process which registered the BroadcastReceiver does exist already, when the system calls the BroadcastReceiver,

  1. 是它在同一个进程?
  2. 而因为这个过程没有结束,在这个过程中,这些静态数据可以直接使用,对不对?
  3. 在另一方面,如果该过程已被终止,则系统将再次当然与这些静态数据是空启动过程?
  4. 当系统调用的BroadcastReceiver,它会调用的主要活动的onCreate也?

感谢。

推荐答案

1。)不知道你的意思,它注册的BroadcastReceiver的过程。如果您为BroadcastRecevier(名为过程),那么这将是一个过程,其名字来源于形成你的应用程序的包加上name属性(XYZ)创建的。如果使用该名称的过程已经存在,那么一个新的进程将不会创建和你的BroadcastReceiver将现有的进程中创建。

1.) Not sure what you mean by "process which registered the BroadcastReceiver." If you provide a named process for your BroadcastRecevier (), then it will be created in a process whose name comes form your application's package plus the name attribute (XYZ). If a process with that name already exists, then a new process will not be created and your BroadcastReceiver will be created within the existing process.

2)。因此,如果过程仍在存储器,则是正确的,有可能是已经初始化的静态数据。

2.) So if the process was still in memory, then you are correct that there may be static data already initialized.

3)正确,任何静态数据将具有在这种情况下,要重新初始化。

3.) Correct, any static data will have to be reinitialized in this case.

4)。如果的BroadcastReceiver的过程中不存在,则该过程将产生,但是这BroadcastReceiver的将是在这个过程中创建的唯一的东西。没有活动将启动。

4.) If the BroadcastReceiver's process does not already exist, then the process will created, but that BroadcastReceiver will be the only thing created in the process. No Activities will be started.

这使一个活动是主活动的唯一的事情是,它被注册为处理某种意图与android.intent.action.MAIN的作用。这是当一个应用程序是广播的那种意向书上马。用户可以切换到一个已经运行的应用程序,也没有主的活动并没有发挥作用,如用行动主要的意图是不是在这种情况下播出。的一点是,在一个主的活动具有其运行的过程中没有特殊的关系,它不仅具有与特定种类意向的特殊关系。

The only thing that makes an Activity a "main" Activity is that it is registered to handle certain kind of Intent with an action of android.intent.action.MAIN. This is the kind of Intent that is broadcast when an app is "launched." A user can switch to an already running app, and no the "main" Activity does not come into play as an Intent with action MAIN is not broadcast in this case. The point is that at a "main" Activity has no special relation with the process that it runs in. It only has a special relationship with a specific kind of Intent.

这篇关于什么是一个过程BroadcastReceiver的生命周期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆