1

是否可以使用 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);
4

1 回答 1

0

我不知道您要实施什么。但是,您可能认为,每 1 分钟重复一次并不是一个好主意。

您可以尝试在特定事件之后运行它,以便程序避免浪费地使用其资源。

于 2018-04-07T07:44:54.127 回答