20

What happens if I schedule the same periodic job (same job ID) and the Job has already been scheduled? Does it start its period again from the beginning?

For example, I call this method twice:

JobInfo myLongJob = new JobInfo.Builder(
            JOB_ID,
            new ComponentName(context, JobSchedulerLongService.class.getName())
    ).setPeriodic(10000)
     .build();

    jobScheduler.schedule(myLongJob);

Does scheduling the job second time cause the periodic timer to start counting again?

Marcel Bro
  • 4,907
  • 4
  • 43
  • 70
Juan Saravia
  • 7,661
  • 6
  • 29
  • 41

1 Answers1

17

I found it after doing some tests:

Does scheduling the job the second time cause the periodic timer to start counting again?

Yes! and...

It will depend on:

  • If the job is being executed: Will cause the first job to stop (calling onStopJob method) and start again.
  • If the job is not being executed: Will just start again the countdown.

Added really useful comment from @Gauthier:

jobId - int: Application-provided id for this job. Subsequent calls to cancel, or jobs created with the same jobId, will update the pre-existing job with the same id. [link to this doc](http://developer.android.com/reference/android/app/job/JobInfo.Builder.html#JobInfo.Builder(int, android.content.ComponentName))

Marcel Bro
  • 4,907
  • 4
  • 43
  • 70
Juan Saravia
  • 7,661
  • 6
  • 29
  • 41
  • 4
    Also worth looking at the JobInfo builder : http://developer.android.com/reference/android/app/job/JobInfo.Builder.html#JobInfo.Builder(int%2C android.content.ComponentName) :jobs created with the same jobId will update the pre-existing job with the same id. – Gauthier May 05 '16 at 20:09
  • 2
    is there any way to check if my job is already scheduled? I will not re-schedule it. – Sandeep Kumar Mar 07 '18 at 17:30
  • @SandeepKumar yes you can use `scheduler.getAllPendingJobs()` check this other question: https://stackoverflow.com/a/46551385/3212266 – Juan Saravia Mar 08 '18 at 01:50