I have two receivers that are listening for android.intent.action.BOOT_COMPLETED
and android.intent.action.PACKAGE_REPLACED
. I was wondering how much battery life they are causing my phone to consume since they cause my app to constantly run now.
A broadcast receiver will always get notified of a broadcast, regardless of the status of your application. It doesn't matter if your application is currently running, in the background or not running at all.
Latest Android Aptitude Question SOLUTION: What is the life cycle of broadcast receivers in android? Options 1) send intent() 2) onRecieve() 3) implicitBroadcast() 4) sendBroadcast(), sendOrderBroadcast(), and sendStickyB.
Broadcast in android is the system-wide events that can occur when the device starts, when a message is received on the device or when incoming calls are received, or when a device goes to airplane mode, etc. Broadcast Receivers are used to respond to these system-wide events.
What does saving battery have to do with BroadcastReceivers? With Android Nougat, the support for registering three different implicit BroadcastReceivers in your AndroidManifest was removed. With apps targeting Android O, all implicit BroadcastReceivers registered in the manifest (except these) will stop working.
The broadcast receivers themselves will not directly consume much battery life. BOOT_COMPLETED
happens once; PACKAGE_REPLACED
happens only on an application upgrade. Those probably average one event per day.
Now, if those broadcast receivers do other stuff, such as starting services, that may have significant battery implications...but that is a problem with your services, not with the receivers themselves.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With