Search code examples
androidbroadcastreceiverandroid-broadcast

Are broadcasts queued or dropped in broadcast receivers (android)?


Looking at the docs:

https://developer.android.com/guide/components/broadcasts

it's not clear ((at least) to me) whether or not broadcasts are processed sequentially, in parallel or dropped (in case the broadcast receiver receives a broadcast but has yet to finish processing the previous one).


Solution

  • whether or not broadcasts are processed sequentially, in parallel or dropped

    Broadcasts are based on publish-subscribe design pattern.

    The onReceive method runs in the main thread, so it runs sequentially. Android system will enqueue all the broadcasts until they're delivered to your receiver, so that none of them gets dropped.

    Additionally, there is a timeout of 10 seconds for the onReceive method after which android considers the receiver to be blocked. So, if your onReceive method takes too long for a single broadcast, android will block/kill it and the subsequent broadcast messages will be missed/dropped.