3

根据这个例子,我看到我现在可以使用 Trigger.NOW 或时间 0,0 开始工作:

Bundle myExtrasBundle = new Bundle();
myExtrasBundle.putString("some_key", "some_value");

Job myJob = dispatcher.newJobBuilder()
    // the JobService that will be called
    .setService(MyJobService.class)
    // uniquely identifies the job
    .setTag("my-unique-tag")
    // one-off job
    .setRecurring(false)
    // don't persist past a device reboot
    .setLifetime(Lifetime.UNTIL_NEXT_BOOT)
    // start between 0 and 60 seconds from now
    .setTrigger(Trigger.executionWindow(0, 60))
    // don't overwrite an existing job with the same tag
    .setReplaceCurrent(false)
    // retry with exponential backoff
    .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
    // constraints that need to be satisfied for the job to run
    .setConstraints(
        // only run on an unmetered network
        Constraint.ON_UNMETERED_NETWORK,
        // only run when the device is charging
        Constraint.DEVICE_CHARGING
    )
    .setExtras(myExtrasBundle)
    .build();

dispatcher.mustSchedule(myJob);

我的问题是:

如何将作业设置为现在开始,但每隔[时间间隔]重复一次(让我们称之为 15 分钟)

4

1 回答 1

0

要定期重复您的工作,请调用以下两种方法:

.setRecurring(true) //true mean repeat it
.setTrigger(Trigger.executionWindow(start, end))

start: 被称为 windowStart,这是作业应该被认为有资格运行的最早时间(以秒为单位)。从安排作业的时间开始计算(对于新作业)

end:被称为 windowEnd,作业应该在理想世界中运行的最晚时间(以秒为单位)。计算方式与windowStart 相同。

于 2017-11-03T15:47:56.663 回答