Skip to content Skip to sidebar Skip to footer

How To Set An Alarmmanager For Preselected Days?

I'm creating an alarm widget, and it works, however, I'm currently using it for a single day, I'd like to know how to define it for predefined days, let's say for example I want to

Solution 1:

Defining them at once i don't know if this can be achieved, but i have another scenario to use. Say that you adjusted the Alarm to fire on Monday, Tuesday , Thursday. you will adjust the AlarmManager just for Monday and on Monday it should fire and checks for the next alarm ( which will be on Tuesday ) and so on. Save all you alarms in a database and take them out one be one and in each alarm check for the next one ( if exists )

Solution 2:

You can use the Calendar.DAY_OF_WEEK api like this:

cal1.set(Calendar.DAY_OF_WEEK,2);  //monday
cal2.set(Calendar.DAY_OF_WEEK,4);  //wednesday
cal3.set(Calendar.DAY_OF_WEEK,6);  //friday

and sets 3 alarmMgr like this:

alarmMgr.set(AlarmManager.RTC_WAKEUP, cal1.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, testThis(this));  // every monday
alarmMgr.set(AlarmManager.RTC_WAKEUP, cal2.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, testThis(this));  // every wednesday
alarmMgr.set(AlarmManager.RTC_WAKEUP, cal3.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, testThis(this));  // every friday

Post a Comment for "How To Set An Alarmmanager For Preselected Days?"