如何使用Firebase Job Scheduler定期启动任务 [英] How to start task periodically using firebase job scheduler
本文介绍了如何使用Firebase Job Scheduler定期启动任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Jobschuler这样每隔x分钟发送一次通知(动态确定)
I used Jobschuler for sending notification every x minutes(determined dynamically) like this
ComponentName componentName = new ComponentName(context,ClsJobService.class);
JobInfo.Builder builder = new JobInfo.Builder(0, componentName)
.setPeriodic(duration * 60 * 1000); //setting in millisecond
JobScheduler jobScheduler = (JobScheduler) context.getSystemService (Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(builder.build());
及其工作原理,它会按JobService中定义的时间发送通知
and its working great it sends notification on time defined in JobService
现在如何将其转换为Firebase Job Scheduler,我确实是这样
now how can I convert it into firebase job scheduler, I did like this
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job job = dispatcher.newJobBuilder()
.setService(ClsJobService.class)
.setTag("notification") // uniquely identifies the job
.setTrigger(Trigger.executionWindow(0, duration * 60))
.setLifetime(Lifetime.FOREVER)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setRecurring(true)
.build();
dispatcher.mustSchedule(job);
但是我仅在安排日程时发送一次通知,之后不发送通知
but I sends notification only once when schedules, and after that not
推荐答案
我最好的猜测是您应该将setTrigger()更改为:
My best guess is that you should change setTrigger() to:
.setTrigger(Trigger.executionWindow(duration * 60, duration * 60))
编辑以修复executionWindow
EDITED to fix executionWindow
这篇关于如何使用Firebase Job Scheduler定期启动任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文