我的应用程序中有一个功能,用户可以设置多个提醒。但问题是,当用户为提醒 A 设置时间而不是为提醒 B 设置时间时,提醒 B 只会被调用。这就是提醒 A 永远不会接到电话的意图。简而言之,只有一个提醒一直在工作。这是设置提醒和呼叫广播的片段。
public void setAlarm(int dayValue, int monthValue, int yearValue, int hourValue, int minValue, String message, int pos){
int ID = 1;
calendar.set(yearValue, monthValue, dayValue, hourValue, minValue, 0);
Calendar tempCal = Calendar.getInstance();
Intent intent = new Intent(context,ReminderNissan.class);
intent.putExtra("title",message);
intent.putExtra("note",message);
intent.putExtra("id", pos);
Log.d("****Indide set alarm method*****", "PSOITION " + pos);
if((tempCal.compareTo(calendar)== -1) || (tempCal.compareTo(calendar)== 0)){
try{
db.open();
db.setAlarm(id.get(pos).toString(), 1);
db.close();
}catch(SQLException exp){
Log.d("SET ALARM OFF SQL EXCEPTION", exp.toString());
}
PendingIntent sender = PendingIntent.getBroadcast(context, ID,intent,0);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
//Toast.makeText(context, "*** ALARM SET AT *** " + pos, Toast.LENGTH_SHORT).show();
}else{
try{
db.open();
db.setAlarm(id.get(pos).toString(), 0);
db.close();
}catch(SQLException exp){
Log.d("SET ALARM OFF SQL EXCEPTION", exp.toString());
}
Toast.makeText(context, "Time Has Alredy Passed. Set proper Time. ", Toast.LENGTH_SHORT).show();
}
}