My App schedules a JobScheduler with a periodic interval of 60 seconds:
val service = ComponentName(packageName, MonitorService::class.java.name)
val job = JobInfo.Builder(JOB_ID, service)
.setPeriodic(interval) // interval is 60*1000
.setPersisted(true)
.setRequiresCharging(false)
.build()
jobScheduler.schedule(job)
I am aware of the fact, that the Android OS optimizes the job scheduler, therefor it will never be scheduled exactly, but with like 2~3 minutes later. I verify this behaviour on my own device (HTC One M8 with Android 6.0).
On many (various) other devices that interval is much more infrequent (like once/twice per hour only).
How can I fix that? Is the Job Scheduler maybe not the correct API for my use case?
The
JobScheduler
minimum period is 15 minutes on newer versions of Android. SeegetMinPeriodMillis()
.In terms of your "use case", doing anything every minute is horrible for battery life. Users have complained very loudly about this, and so Google continues to take steps to prevent apps from doing this. For example, Doze mode and app standby on Android 6.0+ will cause your jobs to run very infrequently, on the order of once an hour or less.