2

我读过所有可用的官方文档(这是令人惊讶的不是很多),所有我能得到定期​​的任务是验证码如何在Firebase JobDispatcher中设置周期性任务的周期?

  .setRecurring(true) 
      // start between 0 and 60 seconds from now 
      .setTrigger(Trigger.executionWindow(0, 60)) 

我知道.setRecurring,使工作周期,而且trigger使它以60秒为间隔开始,但第二次执行的时间呢?这是否意味着第二次也会从第一次开始执行60秒?

这不可能是真实的,因为即使考虑到后台活动的优化以及服务如何比预期晚一点运行,在工作约5/10/20分钟时编程60秒时间后来是太不同了。官方文件表示,差异是几秒钟,也许几分钟不超过20分钟。

基本上,我的问题是这个.setTrigger(Trigger.executionWindow(0, 60))真的意味着这段时间是60秒还是我开始这个错误?

回答

0

如果你看一下触发类的源会更清楚here

它指出:

/** 
 
    * Creates a new ExecutionWindow based on the provided time interval. 
 
    * 
 
    * @param windowStart The earliest time (in seconds) the job should be 
 
    *     considered eligible to run. Calculated from when the 
 
    *     job was scheduled (for new jobs) or last run (for 
 
    *     recurring jobs). 
 
    * @param windowEnd The latest time (in seconds) the job should be run in 
 
    *     an ideal world. Calculated in the same way as 
 
    *     {@code windowStart}. 
 
    * @throws IllegalArgumentException if the provided parameters are too 
 
    *         restrictive. 
 
    */ 
 
    public static JobTrigger.ExecutionWindowTrigger executionWindow(int windowStart, int windowEnd) { 
 
     if (windowStart < 0) { 
 
      throw new IllegalArgumentException("Window start can't be less than 0"); 
 
     } else if (windowEnd < windowStart) { 
 
      throw new IllegalArgumentException("Window end can't be less than window start"); 
 
     } 
 

 
     return new JobTrigger.ExecutionWindowTrigger(windowStart, windowEnd); 
 
    }

或只是按Ctrl +点击Trigger随后的Android Studio会把你带到源头。所以如果你写:.setTrigger(Trigger.executionWindow(0, 60))那么它将每秒运行

1

当它是非周期性的。

.setRecurring(false) 
.setTrigger(Trigger.executionWindow(x, y)) 

该代码将运行的时间从工作X秒被安排和y的工作秒原定之间我们的工作。

X是知道的windowStart,这是最早的时候(以秒为单位)的工作应该被视为符合运行条件。从当定(新工作)

Ÿ是知道的windowEnd,最新的时间(单位:秒)的工作应该在一个理想的世界运行的作业计算。以与windowStart相同的方式计算。

当是周期性

.setRecurring(true)    
.setTrigger(Trigger.executionWindow(x, y)) 

该代码将运行的时间从工作X秒被安排和y的工作秒是我们之间的工作scheduled.Since这是周期性的下执行将在作业完成后安排x秒。

可能也指this也回答。