22

If I use the AlarmManager to schedule an alarm (a PendintIntent which should be send), how can I identify that alarm later to cancel it? Can I cancel all alarms scheduled by my app?

cody
  • 5,377
  • 13
  • 47
  • 69

1 Answers1

37

You probably want to have a closer look at the AlarmManager.cancel(PendingIntent operation) function.

Julian
  • 18,744
  • 14
  • 70
  • 100
  • 3
    was just writing that as well :). This is the right answer. For operation you need to use the same one or what needs to match with the first one is: data, type, class, and categories. – Patrick Boos Nov 18 '10 at 08:27
  • 1
    Thanks, so I have to save a reference to the pending intent, but what if my app is finished? How to cancel the alarms on the next start? – cody Nov 18 '10 at 08:42
  • If I could cancel all alarms set by my app that would solve that problem easily.. – cody Nov 18 '10 at 08:44
  • 7
    @cody: you'd have to re-create the `PendingIntent` if you want to cancel the alarms on the next start. I don't think there is an easy way to cancel all alarms set by your app. The documentation for the `cancel` function says: *any alarm, of any type, whose Intent matches this one (as defined by filterEquals(Intent)), will be canceled.* You should take a look at the documentation for `filterEquals(Intent)`, as this will explain to you the specifics of how this works. – Julian Nov 18 '10 at 08:54