我有应用程序让人想起他们的任务.所以有一个待定的意图,现在用户可以在他想要的时候删除alram.在这段代码中,只有一个用于多个用户警报的等待意图,所以我很失望地取消了特殊的警报,其中“额外”是“药丸”.剩下的闹钟不应该被取消.我对这个问题没有任何线索.希望我很清楚谢谢
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,但不一定是相同的附件:
public void cancel (PendingIntent operation)
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(意向)
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.