Android JobScheduler: using setMinimumLatency with

2019-08-02 23:18发布

问题:

I'm just playing around with JobScheduler, and have a couple of niggles.

One of them is that, although you can delay a job by using setMinimumLatency(), you cannot use that in combination with setPeriodic(), since an Exception is raised.

I cannot really understand why this is the case... it seems to be reasonable to delay the start of a periodic job, just as it is reasonable to delay the start of a one-off job.

Given that you cannot, what is the best way of scheduling a periodic job that starts in the future (even after a reboot), using JobScheduler?

回答1:

In your implementation of JobService class, call jobFinished(params, reschedule); to reschedule before leaving onStartJob method.

Also don't forget to return true in onStopJob method to reschedule as well.

https://developer.android.com/reference/android/app/job/JobService.html#jobFinished(android.app.job.JobParameters, boolean)