Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android JobScheduler: If you schedule the same job with periodic time, does it start the period again?

Tags:

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?

like image 862
Juan Saravia Avatar asked May 05 '16 20:05

Juan Saravia


People also ask

How does JobScheduler work in Android?

JobScheduler is introduced while the Android set limitation on background Execution. It means that the system will automatically destroy the background execution to save battery and memory. So if you want to perform some background job like some network operations no matter your app is running or not.

What is JobScheduler explain how it works?

android.app.job.JobScheduler. This is an API for scheduling various types of jobs against the framework that will be executed in your application's own process. See JobInfo for more description of the types of jobs that can be run and how to construct them.

What is job scheduling and what are the advantages of using JobScheduler API?

The job scheduler API. The Android 5.0 Lollipop (API 21) release introduces a job scheduler API via the JobScheduler class. This API allows to batch jobs when the device has more resources available. In general this API can be used to schedule everything that is not time critical for the user.


1 Answers

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))

like image 198
Juan Saravia Avatar answered Oct 09 '22 02:10

Juan Saravia