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.
Related videos on Youtube
Author by
cody
Updated on November 18, 2020Comments
-
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 over 13 yearswas 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 over 13 yearsThanks, 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 over 13 yearsIf I could cancel all alarms set by my app that would solve that problem easily..
-
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 thecancel
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 forfilterEquals(Intent)
, as this will explain to you the specifics of how this works.