我的代码有问题。我有日期和时间的列表。我在 for 循环中从 SQLite 获取所有日期和时间。现在,当我运行程序时,AlarmManager 不会在每个日期和时间触发。仅收到最后添加的警报。这里我有代码:
private void setAlarm() {
// TODO Auto-generated method stub
DbHandler dbHandler =new DbHandler(getApplicationContext());
list_alarm = dbHandler.getDateOnly();
Log.d("00000", list_alarm.size()+"");
if(list_alarm.size() > 0){
for(int i=0;i<list_alarm.size();i++){
String dat = list_alarm.get(i).getTaskDate();
String pat = list_alarm.get(i).getTaskTime();
String strDnT = dat+" "+pat;
SimpleDateFormat format;
Date date1;
long d;
format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
try {
date1 = (Date)format.parse(strDnT);
d = date1.getTime();
Intent k = new Intent(Create_Task.this, AlarmReceiver.class);
PendingIntent intent = PendingIntent.getBroadcast(getApplicationContext(), RQS_1, k, 0);
AlarmManager managers = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
managers.set(AlarmManager.RTC_WAKEUP, d, intent);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}else{
Log.d("List : ", "Not having any list");
}
}
提前致谢。我希望你能理解我的问题。