简体   繁体   English

Android JobScheduler:如果您使用定期时间安排相同的作业,它是否会再次开始这段时间?

[英]Android JobScheduler: If you schedule the same job with periodic time, does it start the period again?

What happens if I schedule the same periodic job (same job ID) and the Job has already been scheduled? 如果我安排相同的定期工作(相同的工作ID)并且工作已经安排,会发生什么? Does it start its period again from the beginning? 它从一开始就再次开始吗?

For example, I call this method twice: 例如,我将此方法调用两次:

JobInfo myLongJob = new JobInfo.Builder(
            JOB_ID,
            new ComponentName(context, JobSchedulerLongService.class.getName())
    ).setPeriodic(10000)
     .build();

    jobScheduler.schedule(myLongJob);

Does scheduling the job second time cause the periodic timer to start counting again? 第二次调度作业会导致周期性计时器再次开始计数吗?

I found it after doing some tests: 我做了一些测试后发现它:

Does scheduling the job the second time cause the periodic timer to start counting again? 第二次调度作业会导致周期性定时器再次开始计数吗?

Yes! 是! and... 和...

It will depend on: 这将取决于:

  • If the job is being executed: Will cause the first job to stop (calling onStopJob method) and start again. 如果正在执行作业:将导致第一个作业停止(调用onStopJob方法)并重新开始。
  • If the job is not being executed: Will just start again the countdown. 如果作业没有被执行:将重新开始倒计时。

Added really useful comment from @Gauthier: 从@Gauthier添加了非常有用的评论:

jobId - int: Application-provided id for this job. jobId - int:此作业的应用程序提供的ID。 Subsequent calls to cancel, or jobs created with the same jobId, will update the pre-existing job with the same id. 后续调用取消或使用相同jobId创建的作业将更新具有相同ID的预先存在的作业。 [link to this doc]( http://developer.android.com/reference/android/app/job/JobInfo.Builder.html#JobInfo.Builder(int , android.content.ComponentName)) [链接到此doc]( http://developer.android.com/reference/android/app/job/JobInfo.Builder.html#JobInfo.Builder ( int ,android.content.ComponentName))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM