Search code examples
androidandroid-broadcastreceiveractivity-stack

How does a broadcast receiver work among activities?


I have multiple activities suppose A , B , C , D and all are register to same BroadCastReceiver. While sending the broadcast message in which order activities will receive the broadcast intents. Is it in order like A , B , C , D or random.

Please let me know, give me some suggestions.


Solution

  • You have no control of that, because System dispatches those actions to registered broadcast listeners. You have no any guarantee on the ordering broadcast listeners will be fired at.

    Unless it is ordered broadcast. From 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.