【发布时间】:2018-04-16 09:29:56
【问题描述】:
根据这个例子,我发现我现在可以使用 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 分钟)?
【问题讨论】:
-
使用 AlarmManager 并每 15 分钟启动一次此任务
-
我们实际上正在远离警报管理器
标签: android firebase-job-dispatcher