Are Android's BroadcastReceivers started in a new thread?

前端 未结 5 1308
难免孤独
难免孤独 2020-12-05 00:01

If I have an inner class that extends BroadcastReceiver within my Service class, should I care about synchronization, when the BroadcastRecei

5条回答
  •  攒了一身酷
    2020-12-05 00:39

    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)
    

提交回复
热议问题