所以我想创建一个提醒应用程序,每个提醒都有自己的优先级(在我的情况下:1 =最重要,2 =不太重要,3 =最不重要)。并且我检索时间以将警报设置为Long
纪元时间,并将优先级值设置为String
,并且当有多个提醒同时存在但优先级不同时,我会以较低的优先级来更改提醒的时间用这种方法:
public void setPriority(){
for (int i = 0; i < aLongDateTime.size(); i++){
Long temp = aLongDateTime.get(i);
for (int j = i + 1; j < aLongDateTime.size(); j++) {
if (temp.equals(aLongDateTime.get(j))) {
switch (aPriority.get(i)) {
case "1":
if (!aPriority.get(j).equals(aPriority.get(i))) {
aLongDateTime.set(j, aLongDateTime.get(j)+150000);
}
break;
case "2":
if (aPriority.get(j).equals(aPriority.get(i)) && (!aPriority.get(j).equals("1"))) {
aLongDateTime.set(j, aLongDateTime.get(j)+150000);
}
break;
case "3":
if (aPriority.get(j).equals(aPriority.get(i)) && (!aPriority.get(j).equals("1")) && (!aPriority.get(j).equals("2"))) {
aLongDateTime.set(j, aLongDateTime.get(j)+150000);
}
break;
}
}
}
for (int j = i + 1; j < aLongDateTime.size(); j++) {//in case there are three or more reminders with same time
if (temp.equals(aLongDateTime.get(j))) {
if (aPriority.get(i).equals("2") && !aPriority.get(j).equals("1") && !aPriority.get(j).equals(aPriority.get(i))) {
aLongDateTime.set(j, aLongDateTime.get(j)+150000);
} else if (aPriority.get(i).equals("3") && !aPriority.get(j).equals("1") && !aPriority.get(j).equals("2") && aPriority.get(j).equals("3")) {
aLongDateTime.set(j, aLongDateTime.get(j)+150000);
}
}
}
}
}
然后使用此设置警报:
private void startAlarm(long LTime) {
alarmManagers = new AlarmManager[20];
br = new BroadcastReceiver() {
(My OnReceive method)
};
for (int i = 0; i < remtasklist.size() ; i++) {
registerReceiver(br, new IntentFilter("com.my.project.app"));
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, i, new Intent("com.my.project.app"), PendingIntent.FLAG_UPDATE_CURRENT);
alarmManagers[i] = (AlarmManager) getSystemService(ALARM_SERVICE);
if (alarmManagers[i] != null) {
alarmManagers[i].set(AlarmManager.RTC_WAKEUP, LTime, pendingIntent);
}
pendingIntents.add(pendingIntent);
}
}
问题在于,当同时有两个提醒(或两个以上)时,第一个提醒关闭,而第二个提醒却没有。