我有一个可以提醒人们执行任务的应用程序.因此有一个PendingIntent,现在用户可以在需要时删除警报.在此代码中,只有一个PendingIntent用于多个用户警报,因此我对取消额外意图为"pill"的特定警报感到困惑.剩余的警报不应取消.我对这个问题一无所知.希望我清楚.谢谢
I have an app which reminds people to do their tasks. So there is one PendingIntent, now the user can delete the alarm when he wants to. In this code, there is just one PendingIntent for multiple user alarms so I am confused on cancelling that particular alarm where the intent extras is "pill". The remaining alarms should not be cancelled. I have no clue on this problem. Hope I am clear. Thanks
Intent intent = new Intent(this, AlarmNotifyReceiver.class); intent.putExtra("Name_pill", "pill"); sender = PendingIntent.getBroadcast(this, DatabaseConstants.NOTIFICATION_ID + 1, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(), sender); updateTheFlag(pillName[(pillName.length-1)]);推荐答案
根据Android文档,为了停止警报,您应该创建一个具有相同数据的Intent,但不是必须是相同的附加功能:
According to the Android documentation, in order to stop an alarm, you should create an Intent with the same data, but not necessarily the same extras:
取消公共无效(PendingIntent操作)
public void cancel (PendingIntent operation)
删除具有匹配意图的所有警报.任何警报,其意图与该警报相匹配的任何类型(由 filterEquals(Intent)定义)都将被取消.
Remove any alarms with a matching Intent. Any alarm, of any type, whose Intent matches this > one (as defined by filterEquals(Intent)), will be canceled.
filterEquals(Intent)
布尔布尔过滤器等于(其他Intent)
public boolean filterEquals (Intent other)
确定两个意图是否相同,以实现意图解析(过滤). >即,如果它们的动作,数据,类型,类和类别相同. 这不会比较意图中包含的任何额外数据.
Determine if two intents are the same for the purposes of intent resolution (filtering). > That is, if their action, data, type, class, and categories are the same. This does not compare any extra data included in the intents.
更多推荐
取消AlarmManager的问题
发布评论