Identify and cancel an alarm send to an AlarmManager

19,553

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

Share:
19,553

Related videos on Youtube

cody
Author by

cody

Updated on November 18, 2020

Comments

  • cody
    cody over 3 years

    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?

  • Patrick Boos
    Patrick Boos over 13 years
    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.
  • cody
    cody over 13 years
    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
    cody over 13 years
    If I could cancel all alarms set by my app that would solve that problem easily..
  • Julian
    Julian over 13 years
    @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.