Are Android broadcasts received in order?

前端 未结 4 672
后悔当初
后悔当初 2021-01-04 08:07

If 2 broadcasts, A and B, and sent in that order, does Android guarantee that all interested receivers will receive them in the same order?

4条回答
  •  清酒与你
    2021-01-04 08:24

    Some more info about this question may be found here:

    Broadcast receiver execution.
    https://groups.google.com/forum/#!topic/android-developers/ClIGNuGJUts


    In the above link Dianne Hackborn writes ...

    "A particular receiver can only process one broadcast at a time. As each broadcast happens, it is processed to determine the targets it should go to, and dispatched into the message queue for each target. When a later broadcast is sent, it will generally not be moved ahead of the queue.

    For the screen on/off broadcasts, you can rely on the most recent broadcast you get being the current state of the screen. once everything has settled down. You can't rely on ordering with any other broadcasts, or other broadcast receivers that may also be receiving the broadcasts."


    This article suggests possibly using sendBroadcastSync() for synchronous delivery, but it is not guaranteed.

    Does LocalBroadcastManager deliver events in the order in which the events wer sent?

提交回复
热议问题