6

Simple question, I think. I have the alarm manager instantiated with some allarms set. What happen when the user close the app?

Does the alarm manager still alert me when the alarms are fired? Or the alarm manager object is destroyed with the app?

Because sometimes the alarms are fired and other times not, so I was wondering whether this was the problem.

Daniele Vitali
  • 3,848
  • 8
  • 48
  • 71
  • Take a look at this link: [Alarm][1] [1]: http://stackoverflow.com/questions/11241794/alarm-set-in-app-with-alarmmanager-got-removed-when-app-force-stop – Guilherme Gregores Jan 23 '13 at 18:41

1 Answers1

9

The alarm manager is a system service, and it keeps running after your app is destroyed.

The precision of the alarm might vary, depending on how you set it.

Check the Logcat for the cases where the alarm is fired, but you don't see any effect. ( Maybe is crashing on the background? )

EDIT: A--C is right. Another cause of missing alarms can be the fact that all alarms get wiped on reboot. You can fix this issue by setting up a BroadcastReceiver to listen the boot_completed intent, and re-set the needed alarms.

Community
  • 1
  • 1
Robert Estivill
  • 12,369
  • 8
  • 43
  • 64
  • 5
    Don't forget, Alarms are wiped on reboot. – A--C Jan 23 '13 at 18:32
  • 1
    Oh another small question: an allarm is alarmManager has an intent that fires a service. This service accesses to a dataset in the Application object of the app. Is it correct to use a service or is better a broadcast receiver? – Daniele Vitali Jan 23 '13 at 19:19
  • 1
    I would keep it on a Service to make sure it runs on a background thread. – Robert Estivill Jan 23 '13 at 19:22
  • @RobertEstivill I thought a Broadcast Receiver runs in a separate thread doesn't it? – Daniele Vitali Jan 23 '13 at 19:37
  • No, the onReceive method is always executed on the process main thread. Here are the docs http://developer.android.com/reference/android/content/BroadcastReceiver.html#onReceive%28android.content.Context,%20android.content.Intent%29 – Robert Estivill Jan 23 '13 at 19:45
  • 1
    @RobertEstivill: Do the alarms dies during the app crash? and in case we need to reset the alarms is there a way we can check if the alarm is already set and running? – Basher51 Jul 08 '14 at 03:16