I'm trying to make an app that allows the user to set tasks and alarms or notifications for each task. I have created a 'setAlarm' method below. However, I have an error that whenever I set multiple tasks with alarms, somehow all the previous ones get cancelled and only the most recently set alarm will go off. Do you know whats the problem? My guess is that the 'calendar' instance gets reset every time I call 'setAlarm'. How could I get around this?
public void setAlarm() {
Intent intent1 = new Intent(NewGoal.this, SingleAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(NewGoal.this,
0, intent1, 0);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
if (alarm_time == 10) {
calendar.add(Calendar.SECOND, alarm_time);
} else if (alarm_time == 30 {
calendar.add(Calendar.SECOND, alarm_time)
}
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
Log.i(TEST, "In setAlarm method");
Log.i(TEST, "calendar=" + calendar.MILLISECOND);
}