I searched for 3 days but did not find a solution or a similar problem / question elsewhere. Here is the deal:
1 hour trigger β working correctly
Trigger after 2 hours β Go to 1:23
1 day trigger β Go to ~ 11: 00
So why is AlarmManager so unpredictable and always too soon? Or what am I doing wrong? And is there any other way so that it can work correctly?
So I register my PendingIntent in the AlarmManager (stripped down):
AlarmManager alarmManager = (AlarmManager)parent.getSystemService(ALARM_SERVICE); Intent myIntent = new Intent(parent, UpdateKlasRoostersService.class); PendingIntent pendingIntent = PendingIntent.getService(parent, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT); //Set startdate of PendingIntent so it triggers in 10 minutes Calendar start = Calendar.getInstance(); start.setTimeInMillis(SystemClock.elapsedRealtime()); start.add(Calendar.MINUTE, 10); //Set interval of PendingIntent so it triggers every day Integer interval = 1*24*60*60*1000; //Cancel any similar instances of this PendingIntent if already scheduled alarmManager.cancel(pendingIntent); //Schedule PendingIntent alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, start.getTimeInMillis(), interval, pendingIntent); //Old way I used to schedule a PendingIntent, didn't seem to work either //alarmManager.set(AlarmManager.RTC_WAKEUP, start.getTimeInMillis(), pendingIntent);
It would be great if someone had a solution. Thanks for any help!
Update: 2 hours ago, he worked to start it with an interval of 2 hours, but after that it worked after 1:20 hours. This is getting really weird. I will track the triggers with a log file and post it here tomorrow.
Update: It is expected that PendingIntent will run every 3 hours. From the second line of the log, it seems that the old scheduled PendingIntent is still running:
[2012-5-3 2:15:42 519] Updating Klasroosters [2012-5-3 4:15:15 562] Updating Klasroosters [2012-5-3 5:15:42 749] Updating Klasroosters [2012-5-3 8:15:42 754] Updating Klasroosters [2012-5-3 11:15:42 522] Updating Klasroosters
But I'm sure that I canceled the scheduled PendingIntent before planning a new one. And each PendingIntent is not recreated in the same way, so it should be exactly the same. If not, this thread issue is no longer relevant.