My app uses a BroadcastReceiver and a service to perform background updates. I have created a setting the user can toggle to enable/disable background updates, which basically starts/cancels an AlarmManager that contains an Intent for my BroadcastReceiver.
I also have a receiver setting in the AndroidManifest which uses the BOOT_COMPLETED Broadcast Action. I’ve noticed if I reboot my device, even if I disabled background updates, the background updates start up again.
My question is, I’m assuming I need to check somewhere, on boot, whether the background update setting has been checked or not. Would I do this in the BroacastReceiver or in the Service itself or is there another way to prevent the background updates from starting on boot.
Thanks.
The best answer is for you to use
PackageManagerandsetComponentEnabledSetting()to disable yourBOOT_COMPLETEDBroadcastReceiverwhen you do not want updates and enable when you do. That way, none of your code ever runs at boot time when it is not needed, speeding up the user’s boot process and using a bit less battery.