gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 17:00:45 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com