I am scheduling a recurring job using firebase job dispatcher. But It is not executing.
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);
After spending so much time on stackoverflow and firebase documentation I didn't get any solution. Then I looked into the firebase job dispatcher code and there is a condition for rescheduling jobs. The condition is in GooglePlayReceiver class :
private static boolean needsToBeRescheduled(JobParameters job, int result) {
return job.isRecurring()
&& job.getTrigger() instanceof ContentUriTrigger
&& result != JobService.RESULT_FAIL_RETRY;
}
According to this above condition
- Job should be recurring which is true in my case
- job.getTrigger() should be instanceof ContentUriTrigger. I am confused here because I want to execute my job based on ExecutionWindowTrigger. So how can I give ContentUriTrigger.
- And the last condition is true in my case because when my job is getting done, I am passing false for needsReschedule param value in jobFinished method.
jobFinished method Implementation in JobService class is:
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);
}
}}
So in GooglePlayReceiver 3rd condition(result != JobService.RESULT_FAIL_RETRY;) is true based on this ternary condition needsReschedule ? RESULT_FAIL_RETRY : RESULT_SUCCESS
Please look into this issue and correct me if I am wrong.