Adrian Le Roy Devezin
Adrian Le Roy Devezin

Reputation: 843

How to make a JobService run after an initial delay?

I want to have a JobScheduler schedule a job to run after 5 minutes, and then it will continue to run every 3 minutes. How can i schedule a job with an initial delay?

My current code:

JobInfo.Builder builder = new JobInfo.Builder(32, componentName);
        if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            builder.setPeriodic(SUBSEQUENT_EXECUTION_INTERVAL);
        } else {
            builder.setMinimumLatency(SUBSEQUENT_EXECUTION_INTERVAL);
        }
        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        jobScheduler.schedule(builder.build());

Upvotes: 2

Views: 722

Answers (1)

Adrian Le Roy Devezin
Adrian Le Roy Devezin

Reputation: 843

Well the ideal situation at this time is to use Android Arch's WorkManager. With this you can set an overrideDeadline that runs your task after an initial delay. More info can be found here

Upvotes: 0

Related Questions