Reputation: 107
With AlarmManager you can set an alarm at specific time, and repeat it at specified interval of time
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), 4*60*60*1000, alarmIntent);
In the example the alarm is repeating every 4 hours, but is it possible to set an alarm that trigger at specific time and repeat at specific times? For example: I want to set an alarm that start a service at 9:00 and repeat it at 11:30, 17:30 and 20:00. The service must start all days approximately at these hours.
Any idea?
Upvotes: 1
Views: 1679
Reputation: 9197
why not this way?
long now = calendar.getTimeInMillis();
long time24h = 24*60*60*1000;
long timeAt09_00 = ...; // calculate from now...
long timeAt11_30 = ...; // calculate from now...
alarmMgr1.setInexactRepeating(AlarmManager.RTC_WAKEUP, now , time24h, alarmIntent);
alarmMgr2.setInexactRepeating(AlarmManager.RTC_WAKEUP, timeAt09_00, time24h, alarmIntent);
alarmMgr3.setInexactRepeating(AlarmManager.RTC_WAKEUP, timeAt11_30, time24h, alarmIntent);
Upvotes: 4
Reputation: 22064
You could create 4 alarms which starts at 9:00, 11:30, 17:30 and 20:00 with AlarmManager.setRepeating()
and set repeating interval to be 24 hours (=24*60*60*1000)
Upvotes: 2
Reputation: 18253
Use the AlarmManager.setRepeating()
method.
See AlarmManager Repeat for an example.
Here is the Android documentation also regarding Scheduling Repeating Alarms, with explanation and sample code.
Upvotes: 1