D
D
Dmitry2015-09-03 13:41:29
Android
Dmitry, 2015-09-03 13:41:29

Why does the AlarmManager after restarting the service execute for the first time after 30 seconds?

alarmManager = (AlarmManager) gcontext.getSystemService(gcontext.ALARM_SERVICE);
                alarmManager.setRepeating(
                        AlarmManager.ELAPSED_REALTIME_WAKEUP,
                        System.currentTimeMillis(),
                        SystemClock.elapsedRealtime() + DB.getServiceRepeatTime(),
                        pendingIntent);

There is a service that reads the startup period from the database. In order for the service to work with a new interval, I save the new value to the database and restart the service.
after restart, the AlarmManager fires for the first time after 30 seconds, and then enters the desired interval.
Why does the first operation occur after 30 seconds?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
svsanek, 2015-09-17
@svsanek

What is the sdk version? Carefully read the java doc for AlarmManager - the fact is that starting from version > 19 - there is no guarantee that the AlarmManager will work exactly at the time you specified.
" Note: as of API 19, all repeating alarms are inexact. If your
* application needs precise delivery times then it must use one-time
* exact alarms, rescheduling each time as described above."
This is from the javadoc
I hope I understood the question correctly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question