Reputation: 895
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 .
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,
Thanks.
Upvotes: 1
Views: 4901
Reputation: 48587
BroadcastReceivers
and ContentObservers
are pretty fairly different.
1.) Yes, generally everything you do is in the same process unless very specifically defined not to be.
2.) This question makes no sense. What are you asking?
3.) Again, no sense. What static data?
4.) No. Broadcast Receivers are entirely different from activities. The only thing called when a broadcast receiver receives a broadcast is its onReceive()
method.
Upvotes: 0
Reputation: 2692
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.) So if the process was still in memory, then you are correct that there may be static data already initialized.
3.) Correct, any static data will have to be reinitialized in this case.
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.
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.
Upvotes: 4