How to start task periodically using firebase job scheduler

匆匆过客 提交于 2019-12-12 05:37:33

问题


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());

and its working great it sends notification on time defined in JobService

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


回答1:


My best guess is that you should change setTrigger() to:

.setTrigger(Trigger.executionWindow(duration * 60, duration * 60))

EDITED to fix executionWindow



来源:https://stackoverflow.com/questions/45286008/how-to-start-task-periodically-using-firebase-job-scheduler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!