I have used the same pendingIntent to set multiple alarms using different intentId for each. the alarm is working. Now i want to cancel a particular alarm. If i use the cancel() method i would end up cancelling all the alarms. I want only a specific one to be deleted. Also the user should be able to cancel this alarm even during a second or a third launch. As in when i launch it the second time, i won't be having the same pendingIntent object. Would i have to persist the pendingIntent object? If so, how? and how do i cancel a single alarm from multiple alarms?
You can do it like this,
In your Pending Intent you can pass a unique ID
in place of requestCode
PendingIntent pi = PendingIntent.getBroadcast(context, unique_id, i, 0);
And to cancel you can use the same unique ID to cancel it, using the same Pending Intent.
am.cancel(pi);
For getting more information you can just use StackOverflow or Google, for now I think this answer
will do for you. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With