我正在使用Firebase作业分派器调度周期性作业。但是它没有执行。
Job job = builder.setService(FetchGCMNotificationService.class)
.setTag(FIREBASE_JOB_TAG)
.setRecurring(true)
.setLifetime(Lifetime.FOREVER)
.setReplaceCurrent(true)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setTrigger(Trigger.executionWindow(TimeUnit.MINUTES.toSeconds(9),TimeUnit.MINUTES.toSeconds(10)))
.build();
firebaseJobDispatcher.mustSchedule(job);
花了很多时间在stackoverflow和firebase文档上之后,我没有任何解决方案。然后,我查看了Firebase作业调度程序代码,并且有一个重新调度作业的条件。条件在GooglePlayReceiver类中:
private static boolean needsToBeRescheduled(JobParameters job, int result) {
return job.isRecurring()
&& job.getTrigger() instanceof ContentUriTrigger
&& result != JobService.RESULT_FAIL_RETRY;
}
根据上述条件
jobFinished方法JobService类中的实现是:
public final void jobFinished(@NonNull JobParameters job, boolean needsReschedule) {
if (job == null) {
Log.e(TAG, "jobFinished called with a null JobParameters");
return;
}
synchronized (runningJobs) {
JobCallback jobCallback = runningJobs.remove(job.getTag());
if (jobCallback != null) {
jobCallback.sendResult(needsReschedule ? RESULT_FAIL_RETRY : RESULT_SUCCESS);
}
}}
因此,在GooglePlayReceiver中,基于此三元条件的第三个条件(结果!= JobService.RESULT_FAIL_RETRY;)为trueReschedule? RESULT_FAIL_RETRY:RESULT_SUCCESS
请调查此问题,如果我错了,请纠正我。