0

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

  1. Job should be recurring which is true in my case
  2. 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.
  3. 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.

Himanshu
  • 454
  • 6
  • 14
  • Does the job start if you wait longer? Android 7+ has a minimum 15-minute interval for repeated jobs https://stackoverflow.com/questions/44029455/android-periodic-jobservice-never-starts – atarasenko Oct 16 '18 at 08:04
  • My job is running for 5 or 6 times after that it will not get execute. – Himanshu Oct 22 '18 at 06:45

0 Answers0