我正在使用firebase作业调度程序,并且正在编写一个简单的定期作业,当有互联网连接时,它应该每分钟左右运行一次。我知道作业不能完全按时运行,因为他们想延长电池寿命并允许其他应用程序也能正常工作,但延迟太长了。它可以达到 25 分钟,这与想要的 1 分钟相比太长了。有没有办法让定期作业至少每 3-5 分钟运行一次?
Thix 是我编写周期性任务的方式:
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(MainActivity.this));
Job myJob = dispatcher.newJobBuilder()
// the JobService that will be called
.setService(MyJobService.class)
// uniquely identifies the job
.setTag("my-unique-tag")
.setRecurring(true)
.setLifetime(Lifetime.FOREVER)
// start between 0 and 10 seconds from now
.setTrigger(Trigger.executionWindow(0, 10))
.setReplaceCurrent(true)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
// constraints that need to be satisfied for the job to run
.setConstraints(
// only run on an unmetered network
Constraint.ON_UNMETERED_NETWORK
)
.build();
dispatcher.mustSchedule(myJob);