I am building a task reminder in Java (using Eclipse). The task reminder needs to prompt a reminder at a specific time before the task. Additionally, it needs to repeat every X minutes before the task, and finally at the specific time that the task reminder was set it should then send one last reminder.
For example:
I set a task with title "Deadline JAVA" at "17:00 27-3-2015". I need to set an alarm at "16:00 27-3-2015", and every 5 minutes until "17:00 27-3-2015".
I have this setReminder
method:
new ReminderManager(this).setReminder(mRowId, rCalendar, mCalendar);
mRowId
is the ID from the task, rCalendar
is the time BEFORE the task, so 16:00, and mCalendar
is the final reminder time.
I'm using this code for setReminder:
public void setReminder(Long taskId, Calendar when, Calendar when2) {
Intent i = new Intent(mContext, OnAlarmReceiver.class);
i.putExtra(RemindersDbAdapter.KEY_ROWID, (long) taskId);
int ID = taskId.intValue();
PendingIntent pi = PendingIntent.getBroadcast(mContext, ID, i,
PendingIntent.FLAG_UPDATE_CURRENT);
mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
when.getTimeInMillis(), 300000 , pi);
}
This works. The alarm is starting, and repeating every 5 minutes. Now the hardest part, and where I need some help is to send one final alarm and have the alarm stop repeating. How do I do this?
Edit: Code for mAlarmManager
private AlarmManager mAlarmManager;
public ReminderManager(Context context) {
mContext = context;
mAlarmManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
}