Search code examples
androidandroid-intentbroadcastreceiveripcboot

Does Android system send BOOT_COMPLETED intent multiple times to multiple receiver in one process or just once?


So basically I have two major functionality, A and B in my app, and they both do something on boot. So I made two BroadcastReceiver R1 and R2, both of which receives BOOT_COMPLETED intent. R1 has fairly complicated logic and handles functionality A. R2's logic is really simple and it handles B.

My problem is to decide if I should keep the code cleaner by keeping both Broadcast Receivers and make each of them listen to BOOT_COMPLETED intent, or if I should combine them to increase performance?

How big is the performance hit to receive two of the same intent instead of one? Will the send-receive-intent process happens once or twice in my app?

Also, is BOOT_COMPLETED sent only after the boot is completely finished, when user can launch apps?

Edit: After testing, the difference between receiving the same intents in the same app by two components vs. by one is roughly only a couple milliseconds.


Solution

  • BroadcastReceivers are inherently independent of any Activities.

    • If Activity A and Activity B are part of the same Application, I suggest combining them and using only one BroadcastReceiver.
    • If they are for different apps and you plan on releasing the apps separately then they should remain two different entities.