KJ Newtown
KJ Newtown

Reputation: 347

Android JobScheduler bug: delay is increased after reboot (param minimumLatency)

I am working with Android JobScheduler, using a JobInfo.Builder() to launch my Service at a specified time. Everything works correctly, even when my device enters in sleepmode. But when I restart the device, all the jobs still exist but their delay has been increased, to an astonishing number.

I am creating jobs with specified delay (param minimumLatency) and using the param setPersisited(true) in order to keep the jobs after reboot.

For example let's say I set minimumLatency to 120_000ms. If I don't reboot my task is correctly executed after the specified delay. But if I reboot before the task, my mimimumLatency is increased to roughly 40 Billion milli

I have also tried to setOverrideDeadline() to various delays, it des not help

This is how I create the Job:

JobInfo.Builder(id, componentName)
                .setExtras(bundle)
                .setPersisted(true)
                .setMinimumLatency(initialDelay)
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .build()
                .let {
                   context.getSystemService(JobScheduler::class.java). schedule(it)
                    }

Please let me know if you have a clue about this issue.

Any help will be appreciated. Thanks

Upvotes: 1

Views: 326

Answers (1)

KJ Newtown
KJ Newtown

Reputation: 347

I found the issue and a way to solve it. Maybe this will help someone. It is actually a bug. When the device boots, in the logs I can see that the device's date is december 31st 2016. And then, later on when the internet is connected, the system's date is updated to today's date. So I figured my increased delay is the time between today and Dec. 31st 2016!

I think Android is Starting the JobScheduler service before setting up the date and thus setting them thinking it will be in 1 year and a half. I guess it depends of the devices. I am on Android TV.

Anyway, this was obviously not directly solvable, so I implemented my own rescheduling in my service and I dont keep the persited parameter. And doing it this way is actually better for my project and future required customizations.

Upvotes: 1

Related Questions