Android : Specifying more than one time for AlarmManager.

on Wednesday, March 25, 2015


I'm trying to set off an alarm at 3 specific times in my app. 9am, 3pm and 9pm.



Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 9);
calendar.set(Calendar.MINUTE, 00);
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent)


The above one will set off an alarm at 9 am and repeats everyday, how do I add more times to it?.


Is it a good practice to create 3 calendar objects with the times and add all them to a List, then while iterating through the list, assign each of them to the AlarmManager? i.e



ArrayList< Calendar>Times = new ArrayList<>();

for (int i =0; i < Times.length(); i++){
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, Times[i].getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent)
}

0 comments:

Post a Comment