Android start running JobScheduler at specific time

后端 未结 2 819
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 08:08

I want to start a JobScheduler at a specific time everyday, and finish it after 3 hours.

I have the part of triggering the job every 20 min, and fo

2条回答
  •  误落风尘
    2020-12-29 08:48

    adding setMinimumLatency on jobInfo with the deference of the current time and the target time solves this issue.

    JobInfo jobInfo = new JobInfo.Builder(1, componentName)
                    .setPersisted(true)
                    .setBackoffCriteria(6000, JobInfo.BACKOFF_POLICY_LINEAR)
                    .setMinimumLatency(1000 * 60)
                    .build();
    

    for the example above the scheduler will work after 60 secs.

提交回复
热议问题