Android JobScheduler: using setMinimumLatency with setPeriodic

安稳与你 提交于 2019-12-14 04:20:19

问题


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)



来源:https://stackoverflow.com/questions/39310407/android-jobscheduler-using-setminimumlatency-with-setperiodic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!