0

嗨,我是android开发的新手,我正在开发一个与警报相关的应用程序,notification而我在特定时间设置警报时一切正常,警报通知正确,但警报notification有时会重复,而我不重复它我怎样才能避免这个问题.

这是我的代码:

Intent intent = new Intent(this, AlarmReceiver.class);
intent.putExtra("ti", name);
intent.putExtra("id", id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);      
final Calendar cal = Calendar.getInstance();        
switch(Cun.valueOf(repeat)) {
case No:        
 alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);
 break;
}
4

1 回答 1

0

警报第一次通知后,使用取消它:

Intent intent = new Intent(this, AlarmReceiver.class);
intent.putExtra("ti", name);
intent.putExtra("id", id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE); 
alarmManager.cancel ( pendingIntent );
于 2013-04-08T12:44:10.703 回答