0

When a user logs into my app I create an AlarmService to be fired in 10 minutes. In response to the alarm, I start a service that polls some data. After polling the service sets itself up with a new Alarm to fire again in another 10 minutes. This works great, but what exactly happens when the users phone gets shut off? Does the alarm wait until the phone is restarted? Or does the alarm get destroyed? How do I go about handeling this situation so the alarm can continue when the user restarts their phone?

James Fazio
  • 6,370
  • 9
  • 38
  • 47

2 Answers2

2

you can't get an alarm work when the phone is off, but you can detect when the phone boot and do something in that moment, like calculate the time remaining to make something.

This link could help you: Trying to start a service on boot on Android

Hope to help :)

Community
  • 1
  • 1
Litus
  • 632
  • 6
  • 11
1

If the user fully powers down the phone, your alarms are wiped out. Usually, the solution is to register a BroadcastReceiver to get control at boot time via the BOOT_COMPLETED broadcast, to go in and set up your alarm(s) again. Here is a sample app demonstrating this.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491