8

I'm using a JobScheduler.setPeriodic() to repeat my JobIntentService. It works the first time but never repeats. Running on Android 7.0

ConcurrentCheck.java

int mdelaymilles  = 30000;
JobScheduler jobScheduler = (JobScheduler) mActivity.getSystemService(JOB_SCHEDULER_SERVICE);
        ComponentName componentName = new ComponentName(mActivity, ConcurrentCheckService.class);
        JobInfo jobInfo = new JobInfo.Builder(JOB_ID, componentName)
                .setPeriodic(mdelaymilles)
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .build();
        int resultCode = jobScheduler.schedule(jobInfo);
        if (resultCode == JobScheduler.RESULT_SUCCESS) {
            Log.d(LOG_TAG, "Job scheduled!");
            Intent intent = new Intent();
            intent.putExtra(LAST_POSITION, lastPosition);
            JobIntentService.enqueueWork(mActivity, ConcurrentCheckService.class, JOB_ID, intent);
        } else {
            Log.d(LOG_TAG, "Job not scheduled");
        }
galaxigirl
  • 2,390
  • 2
  • 20
  • 29

1 Answers1

18

The minimum period a job can be scheduled is 15 minutes. If it is set to a value less than 15 minutes, the job will use 15 minutes.

See: MIN_PERIOD_MILLIS in JobInfo.

Also, see this comment in the code too:

Query the minimum interval allowed for periodic scheduled jobs. Attempting to declare a smaller period that this when scheduling a job will result in a job that is still periodic, but will run with this effective period. A recurring task with your interval will need some other service, possibly the Alarm Manager will work for you.

Steve Miskovetz
  • 2,360
  • 13
  • 29
  • and what is the maximum periodic interval we can set in that? – Cyph3rCod3r May 11 '18 at 18:01
  • 1
    The intervalMillis parameter to setPeriodic is of type long. So I suppose 2^63 -1 is the max (whatever number in milliseconds that is), but I prefer the description, "longer than a lifetime" in this context. – Steve Miskovetz May 11 '18 at 23:24