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?
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.
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.
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.
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:
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With