我正在使用不同的ID创建多个警报,假设我创建了警报1,2,3,我只想取消2。你能指导我怎么样?我确实搜索了SO,但我没有发现任何关于是否必须在取消警报时将“相同的额外数据”添加到待处理状态,所以我想我会问你,看看你会怎么做
以下是我创建闹钟的方法
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent broadcast_intent = new Intent(this, AlarmBroadcastReceiver.class);
broadcast_intent.putExtra("Tag", Object1);
broadcast_intent.putExtra("Tag2", Object2);
for(int i=1;i<=3;i++){
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, i, broadcast_intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.RTC_WAKEUP, triggerAtTime, pendingIntent);
}
如何取消闹钟2?
答案 0 :(得分:0)
它为我工作:-----
buttonCancel.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
pendingIntent = PendingIntent.getBroadcast(AndroidAlarmService.this, 0, broadcast_intent ,PendingIntent.FLAG_CANCEL_CURRENT);
alarmManager.cancel(pendingIntent);
// Tell the user about what we did.
Toast.makeText(AndroidAlarmService.this, "Cancel!", Toast.LENGTH_LONG).show();
}});