取消当你有多个报警单个报警 [英] Cancelling a single alarm when you have multiple alarms
问题描述
我已经使用了相同的pendingIntent使用不同intentId每个设置多个报警。报警工作。现在我想取消特定的报警。如果我用cancel()方法,我会最终取消所有报警。我想仅特定的一个被删除。另外,用户应该能够即使在第二或第三个发射取消此报警。由于当我推出来的第二次,我不会再有同样的pendingIntent对象。那么我有坚持的pendingIntent对象?如果是这样,怎么样?而如何从多个报警取消单个报警?
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?
推荐答案
您可以像这样,
在你的等待意向,你可以通过一个的唯一ID
在请求code
In your Pending Intent you can pass a unique ID
in place of requestCode
PendingIntent pi = PendingIntent.getBroadcast(context, unique_id, i, 0);
和取消,您可以使用相同的唯一ID来取消它,使用相同的待定意向。
And to cancel you can use the same unique ID to cancel it, using the same Pending Intent.
am.cancel(pi);
有关让你可以使用计算器或谷歌的详细信息,现在我觉得<一个href="http://stackoverflow.com/questions/3273342/how-can-i-setup-multiple-alarms-in-android"><$c$c>this答案 会为你做。 :)
For getting more information you can just use StackOverflow or Google, for now I think this answer
will do for you. :)
这篇关于取消当你有多个报警单个报警的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!