android - 广播接收器如何在 Activity 之间工作?

标签 android android-broadcastreceiver activity-stack

我有多个 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/

相关文章:

java - 应用程序已停止-Android studio

android 在 surfaceview onDraw 中显示 toast

android - 使用自定义 broadcastreceiver 接收 Parse 通知

android - 电话状态的广播接收器更改不工作

android - 当子 Activity 关闭时更新 Activity

Android在相对布局中使按钮成为屏幕宽度和高度的1/3

java - 为什么我们必须从一个小部件更新多个小部件?

android - 完成特定 Activity 的所有实例

java - 从android中的堆栈中删除一个 Activity

android - 将所有内容的 linearLayout 更改为 dark