[英]How to start task periodically using firebase job scheduler
I used Jobschuler for sending notification every x minutes(determined dynamically) like this 我使用Jobschuler每隔x分钟发送一次通知(动态确定),就像这样
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());
and its working great it sends notification on time defined in JobService 它的工作原理很好,它可以按JobService中定义的时间发送通知
now how can I convert it into firebase job scheduler, I did like this 现在如何将其转换为firebase Job Scheduler,我确实是这样
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 但我只在安排时间表时发送一次通知,之后不发送
My best guess is that you should change setTrigger() to: 我最好的猜测是您应该将setTrigger()更改为:
.setTrigger(Trigger.executionWindow(duration * 60, duration * 60))
EDITED to fix executionWindow 编辑以修复executionWindow
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.