Planning for JobScheduler on Android

I have a problem scheduling jobs with JobScheduler in the new Android API 21. This is the code that I schedule a job with an interval of 60 seconds, as shown below:

ComponentName serviceName = new ComponentName(this, MyJobService.class); JobInfo jobInfo = new JobInfo.Builder(0, serviceName) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) .setPeriodic(60000) .build(); 

My JobService prints only the runtime in Logcat, but the log shows that the service starts at these points:

 03-18 08:37:26.334: I/JOB(32662): Wed Mar 18 08:37:26 BRT 2015 03-18 08:37:56.364: I/JOB(32662): Wed Mar 18 08:37:56 BRT 2015 03-18 08:39:21.418: I/JOB(32662): Wed Mar 18 08:39:21 BRT 2015 03-18 08:41:51.670: I/JOB(32662): Wed Mar 18 08:41:51 BRT 2015 03-18 08:45:52.192: I/JOB(32662): Wed Mar 18 08:45:52 BRT 2015 03-18 08:54:20.678: I/JOB(32662): Wed Mar 18 08:54:20 BRT 2015 

It’s strange, because the task must be executed at least 1 time within 1 minute when I set the setPeriodic (60000) method. It is also curious how the interval between runs increases. At this moment the time is cf. March 18, 09:09:00 BRT 2015, and Job are no longer running.

Is this a problem with the JobScheduler API? (I work in Nexus 5 with Android 5.0.1)

+7
android jobs scheduling task
source share
2 answers

The time change is related to the Back-Off criteria for repeated tasks. By default, it is set to exponential. I assume that you too did not finish your work correctly when you finish with it by typing jobFinished(JobParameters params, boolean needsReschedule) .

I wrote a post that focuses on all the details with JobScheduler. I highly recommend reading it.

+8
source share

I had the same problem, and I think it could be due to the internal requirements of the JobInfo class:

  /* Minimum interval for a periodic job, in milliseconds. */ private static final long MIN_PERIOD_MILLIS = 15 * 60 * 1000L; // 15 minutes 

JobInfo does not seem to allow spacing less than this.

+3
source share

All Articles