使用Firebase JobDispatcher永远每1分钟运行一次服务是否可以。重复任务的推荐间隔是什么?
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job myJob = dispatcher.newJobBuilder()
// the JobService that will be called
.setService(NotificationService.class)
// uniquely identifies the job
.setTag("MU_TAG")
// one-off job
.setRecurring(true)
// don't persist past a device reboot
.setLifetime(Lifetime.FOREVER)
// start between 0 and 60 seconds from now
.setTrigger(Trigger.executionWindow(60, 60 + 1))
// don't overwrite an existing job with the same tag
.setReplaceCurrent(true)
// retry with exponential backoff
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.build();
dispatcher.mustSchedule(myJob);
答案 0 :(得分:0)
我不知道你要实施的是什么。但是,正如您所想,每1分钟重复一次并不是一个好主意。
您可以尝试在特定事件之后运行它,以便程序避免浪费地使用其资源。