0

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.

Kris B
  • 3,436
  • 9
  • 64
  • 106

1 Answers1

1

The best answer is for you to use PackageManager and setComponentEnabledSetting() to disable your BOOT_COMPLETED BroadcastReceiver when 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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks, I just realized my question is probably a duplicate of this question: http://stackoverflow.com/questions/2782448/android-how-to-start-a-service-at-boot-based-on-user-settings – Kris B Mar 18 '12 at 15:03
  • @KrisB: In particular, [this answer](http://stackoverflow.com/a/3465986/115145) on that question is good. – CommonsWare Mar 18 '12 at 15:08
  • definitely, the accepted answer to that question seems a little hacky. :) – Kris B Mar 18 '12 at 15:10