Reputation: 3001
I have a working example of a service that gets notified form an alarm manager object, the interval changes according to the user's preferences, this works fine when the interval is 5-10-20-30 minutes but when I schedule an alarm for one hour my service is never notified,is there any known bug about that? shouldn't the alarm notifies my service?
Upvotes: 0
Views: 1461
Reputation: 13846
Check the AlarmManager
documentation, there is a INTERVAL_HOUR
constant that would be better to use in this case.
Upvotes: 2
Reputation: 482
My only suggestion is to make sure you're representing 1 hour as 3,600,000 milliseconds.
I use the following in my method to set my alarm every 15 minutes from the top of the hour starting at 00:00 the same day rather than when the alarm is created.
// Set (or get) long time
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long START_TIME = calendar.getTimeInMillis();
// Variables
int LONG_INTERVAL = 15; // in minutes
// Set the repeating alarm
aManager.setRepeating(AlarmManager.RTC_WAKEUP, START_TIME, LONG_INTERVAL * 60000, sender);
Rather than waiting an entire hour to test, I just set HOUR_OF_DAY and MINUTE to show roughly 55 minutes "ago" so that it would run at the next expected interval. Everything was successful when I tested.
Upvotes: 0