问题描述
如果我在我的 Service
类中有一个扩展 BroadcastReceiver
的内部类,我是否应该关心同步,当 BroadcastReceiver
类读取/从 Service
类写入对象?或者换一种说法:BroadacstReceiver
的 onReceive()
方法是否在一个额外的线程中启动?
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?
推荐答案
onReceive() 方法始终在主线程(也称为UI 线程")上调用,除非您要求将其安排在使用 registerReceiver() 变体的不同线程:
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)
这篇关于Android 的 BroadcastReceivers 是否在新线程中启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!