Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When your BroadcastReceiver is invoked via an Intent, what process does it run on?

I know that we have 10 seconds to handle an intent; otherwise, watch dog timer will kick in. And its suppose be a light-weight function. So my question is, does the BroadcastReceiver run in the same process as your root activity? Or does it run on Zygote system process?

like image 676
Takeshi Kaga Avatar asked Nov 02 '10 01:11

Takeshi Kaga


People also ask

Which Intent is used by BroadcastReceiver?

Creating a BroadcastReceiverThe intent object is passed with all the additional data. A Context object is also available and is used to start an activity or service using context. startActivity(myIntent); or context. startService(myService); respectively.

What is the life cycle of BroadcastReceiver?

A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent) . Once your code returns from this function, the system considers the object to be finished and no longer active.

What is the method name in BroadcastReceiver receive the message?

onReceive. This method is called when the BroadcastReceiver is receiving an Intent broadcast.

What is Intent How are they used to broadcast and receive events?

Broadcasting Events with IntentsSet the action, data, and category of your Intent in a way that lets Broadcast Receivers accurately determine their interest. In this scenario, the Intent action string is used to identify the event being broadcast, so it should be a unique string that identifi es the event.


1 Answers

So my question is, does the BroadcastReceiver run in the same process as your root activity?

Yes. And, as xandy notes, it also runs on the main application thread. Your BroadcastReceiver should either do its work very quickly or call startService() on an IntentService (or something) that can do long-running work on a background thread.

BTW, I am pleased to see that you have time to spend on Android application development, now that you are no longer busy saving the world. It must be nice to spend time on a hobby and not worry about being shot at, blown up, etc. :-)

like image 130
CommonsWare Avatar answered Oct 05 '22 23:10

CommonsWare