Reputation: 47
I'm creating an app that, after receiving a text from a certain number, starts a repeating alarm using AlarmManager. The AlarmReciever plays an alarm sound for thirty seconds and then the alarm repeats every five minutes. I want to cancel the AlarmManager when the app is closed and restarted by the user but I have to use the same instance of the alarmIntent to cancel it.
Upvotes: -1
Views: 263
Reputation: 1007322
I have to use the same instance of the alarmIntent to cancel it.
No, you have to use an equivalent PendingIntent
to cancel it. By "equivalent", I mean:
getActivity()
)Intent
By "equivalent Intent
", I mean that all the routing information is the same (component, action, data, MIME type, categories). Extras do not matter.
You need to hold onto enough information in a persistent data store (e.g., file) to be able to create an equivalent PendingIntent
to pass to cancel()
on AlarmManager
.
Upvotes: 3