mercredi 11 mars 2015

Use Java Calendar to set Alarm for next week



I am developing a weekly alarm app in Android where I let the user set the alarm to go off on a certain day of the week. For example:



Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);

alarmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);


What I don't understand how to do is set the alarm to go off next week if the day of the week has already passed. For example if it's Wednesday and the user sets an alarm for Monday I want it to set an alarm for next Monday but instead what happens is the alarm goes off right when I call the set method. What can I do to schedule it for the next week?




Aucun commentaire:

Enregistrer un commentaire