是否在新线程中启动

是否在新线程中启动

本文介绍了Android 的 BroadcastReceivers 是否在新线程中启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在我的 Service 类中有一个扩展 BroadcastReceiver 的内部类,我是否应该关心同步,当 BroadcastReceiver 类读取/从 Service 类写入对象?或者换一种说法:BroadacstReceiveronReceive() 方法是否在一个额外的线程中启动?

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 是否在新线程中启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 02:02