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?
Identify and cancel an alarm send to an AlarmManager
Asked Answered
You probably want to have a closer look at the AlarmManager.cancel(PendingIntent operation)
function.
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. –
Lukelukens
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? –
Hindmost
If I could cancel all alarms set by my app that would solve that problem easily.. –
Hindmost
@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. –
Orelu © 2022 - 2024 — McMap. All rights reserved.