我正在開發一個警報應用程序,因爲我使用的警報管理器概念,該用戶可以選擇不。 (例如,他選擇5天后警報將在5天之前)比較天數列表來自sqlite數據庫。我寫了一些代碼其工作問題是,當用戶更改警報剩餘天數(例如, 3而不是5)設置之前(5天)警報不清楚總共有8個警報出現(5 + 3)請任何人解決我的問題。如何清除報警管理器中的先前報警?
dbcal.set(currentcal.get(Calendar.YEAR), mnth,dt);
Log.e("dbCal Alarm","first"+dbcal.getTime());
if(!dbcal.getTime().before(currentcal.getTime())){
uniqueno++;
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(SampledateActivity.this,AlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(SampledateActivity.this, uniqueno, intent, 0);
alarmManager.set(AlarmManager.RTC_WAKEUP, dbcal.getTimeInMillis(), pi);
}
for(int k = 1 ; k <= time ;k++){
Log.e("Entered to alarm","yes");
dbcal.add(Calendar.HOUR, -24);
if(!dbcal.getTime().before(currentcal.getTime())){
uniqueno++;
Intent intentlocal = new Intent(SampledateActivity.this,AlarmReceiver.class);
PendingIntent pilocal = PendingIntent.getBroadcast(SampledateActivity.this, uniqueno, intentlocal, 0);
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, dbcal.getTimeInMillis(), pilocal);
Log.e("dbCal Alarm","k: "+"k value:"+k+(time*i+k)+":"+dbcal.getTime());
}
}
下面的URL可能對您有所幫助 http://stackoverflow.com/questions/7933669/two-buttons-with-pendingintents-widget – 2012-02-15 12:17:17