问题描述
如果我有一个扩展的内部类的BroadcastReceiver
在我的服务
类,我应该关心的同步,当在的BroadcastReceiver
类读取/从服务
类写入对象?或者换用另一种方式:是 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!