This code sets an alarm to fire at a specified day & time and repeats every 20 minutes. Can I stop the repeat (when the user stops it or when it successfully performs a job) but keep the alarm set without having to reinitialize ?
Example, the following sets an alarm to fire at 8:30 am & repeats every 20 min after, if the user stops the alarm, I would like the alarm to fire the next day at 8:30 again
private AlarmManager alarmMgr;
private PendingIntent alarmIntent;
...
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmListener.class);
alarmIntent = PendingIntent.getBroadcast(context, AlarmListener.REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Set the alarm to start at 8:30 am
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 30);
// 20 minutes repeating.
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
60 * 1000 * 20, alarmIntent);
A use case of this would be a monthly reminder where you set an Alarm for the 25th of every month. On the 25th, your Alarm would fire and repeat every 20 min but when you stop it, it should keep the schedule of firing an alarm on the 25th !
Also, any optimizations, notices or warnings regarding using AlarmManager would be highly appreciated.