I am currently working on an android app with a reminder service. I am using AlarmManager. I have successfully been able to set the alarm to run when the user clicks a button. But I want it to run from a start day to a finish day. But right now, it appears to just run forever.
I already have this:
private void setAlarm(String startDate,String endDate, String startTime, Context ctx, long id, int frequency){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, Utility.getYear(startDate));
calendar.set(Calendar.MONTH, Utility.getMonth(startDate));
calendar.set(Calendar.DAY_OF_MONTH, Utility.getDay(startDate));
calendar.set(Calendar.HOUR_OF_DAY, Utility.getHour(startTime));
calendar.set(Calendar.MINUTE, Utility.getMinute(startTime));
Intent intent = new Intent(ctx,AlarmReceiver.class);
intent.putExtra("ID", (int)id);
intent.setAction(""+System.currentTimeMillis());
PendingIntent mPendingIntent = PendingIntent.getBroadcast(ctx, (int) id, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), (AlarmManager.INTERVAL_DAY / frequency), mPendingIntent);
}
The alarm works. I just need to set it to be able to stop when the endDate has been reached. Thanks.