katwal-dipak
katwal-dipak

Reputation: 3691

How to reschedule JobScheduler?

How to reschedule JobScheduler that I started with setPeriodic(), I want to change the scheduler time later with user input.

JobInfo.Builder builder =
    new JobInfo.Builder(JOB_ID, new ComponentName(this, MyJobScheduler.class));
builder
   .setPeriodic(15000)
   .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
   .setPersisted(true);
jobScheduler.schedule(builder.build());

Upvotes: 2

Views: 5857

Answers (2)

greywolf82
greywolf82

Reputation: 22193

If you want to change the parameter later, you can do exactly as you wrote. However, you must use exactly the same job id. The system will update the job.

Upvotes: 3

ucsunil
ucsunil

Reputation: 7504

Currently, there is no option to reschedule a job. What you can do is call the cancel() method to cancel the job with the given job id and schedule a new job. So it would look something like:

jobScheduler.cancel(JOB_ID);
// Construct a new JobInfo.Builder
jobScheduler.schedule(builder.build());

Upvotes: 3

Related Questions