Are Android's BroadcastReceivers started in a new thread?

Flow picture Flow · Mar 22, 2011 · Viewed 22.5k times · Source

If I have an inner class that extends BroadcastReceiver within my Service class, should I care about synchronization, when the BroadcastReceiver class reads/writes to objects from the Service class? Or to put it in another way: Are BroadacstReceiver's onReceive() Methods started in an extra thread?

Answer

Nick Pelly picture Nick Pelly · Mar 3, 2012

The onReceive() method is always called on the main thread (which is also referred to as "UI thread"), unless you requested it to be scheduled on a different thread using the registerReceiver() variant:

Context.registerReceiver(BroadcastReceiver receiver,
                         IntentFilter filter,
                         String broadcastPermission,
                         Handler scheduler)