最初にアラームを設定したときになぜアラームが鳴ったのか、もう一度設定しようとしても鳴らないのか、非常に混乱しています。しかし、3回目は機能し、5日目、7日目、9日目などもそうです.2回ごとにアラームを設定します。保留中のインテントに具体的に uniqID を指定したため、これが起こらないように完全に混乱しています。
setAlarm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
myCal.set(Calendar.YEAR, datePicker.getYear());
myCal.set(Calendar.MONTH, datePicker.getMonth());
myCal.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
myCal.set(Calendar.HOUR, timePicker.getCurrentHour());
myCal.set(Calendar.MINUTE, timePicker.getCurrentMinute());
myCal.set(Calendar.SECOND, 0);
//precaution if the user restarts their phone. Saves the alarm to a file
//and when user restarts their phone register a broadcast receiver to pick up
//the broadcast and then re-create the alarms that were stored.
setAlarms(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()
, timePicker.getCurrentHour(), timePicker.getCurrentMinute(), assignmentName);
Intent triggered = new Intent(ManageAlarms.this, alarms.DisplayNotification.class);
triggered.putExtra("NotificationId", 1);
triggered.putExtra("assignmentName", assignmentName);
PendingIntent displayIntent = PendingIntent.getActivity(
ManageAlarms.this, counter, triggered, PendingIntent.FLAG_ONE_SHOT);
/*boolean alarmActive = (PendingIntent.getActivity(getBaseContext(), 0,
triggered, PendingIntent.FLAG_NO_CREATE) != null);
if (alarmActive) {
alarmManager.cancel(displayIntent);
}*/
alarmManager.set(AlarmManager.RTC_WAKEUP,
myCal.getTimeInMillis(), displayIntent);
counter++;