我有多个 Activity ,假设 A、B、C、D 都注册到同一个 BroadCastReceiver。在发送广播消息时, Activity 将按哪个顺序接收广播 Intent 。是像 A , B , C , D 这样的顺序还是随机的。
请告诉我,给我一些建议。
最佳答案
您无法控制它,因为系统会将这些操作分派(dispatch)给已注册的广播监听器。您无法保证将触发广播听众的顺序。
除非是命令广播。来自 docs :
The sendOrderedBroadcast(Intent, String) method sends broadcasts to one receiver at a time. As each receiver executes in turn, it can propagate a result to the next receiver, or it can completely abort the broadcast so that it won't be passed to other receivers. The order receivers run in can be controlled with the android:priority attribute of the matching intent-filter; receivers with the same priority will be run in an arbitrary order.
关于android - 广播接收器如何在 Activity 之间工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43144763/