Android JobScheduler runs for 1 minute

I am trying to implement a background refresh service with the new JobScheduler (compat by tatarka). Here is my service

@Override public boolean onStartJob(JobParameters params) { Timber.i("on start job: " + params.getJobId()); return true; } @Override public boolean onStopJob(JobParameters params) { Timber.i("on stop job: " + params.getJobId()); return true; } 

Here is my JobInfo

 public void scheduleJob(View v) { JobInfo job = new JobInfo.Builder(kJobId++ /*jobid*/, new ComponentName(getActivity(), RefreshJobService.class)) .setPeriodic(2000) .build(); mTestService.scheduleJob(job); } 

In the magazine, I see that my work always works for 1 minute 12-31 12:38:03.884 10059-10059/@/RefreshJobService﹕ on stop job: 0 12-31 12:39:03.891 10059-10059/@/RefreshJobService﹕ on start job: 0 12-31 12:40:03.911 10059-10059/@/RefreshJobService﹕ on stop job: 0 12-31 12:42:08.841 10059-10059/@/RefreshJobService﹕ on start job: 0 12-31 12:43:08.858 10059-10059/@/RefreshJobService﹕ on stop job: 0

So why? I set a periodic value of 2000 ms, any value does not affect the 1 minute interval for operation. Why?

+8
android android-jobscheduler
source share
5 answers

So far, Android 5.1.1 has not had a timeout of 60 seconds for one job. Starting with Android 6, the waiting time is 10 minutes.

+6
source share

onStopJob is called when the system wants to cancel your work. The reason he cancels your work is because she thinks she is still working. You need to call jobFinished(params, bool) at some point in your job to tell the scheduler that it has completed, otherwise it will shut down and call onStopJob to cancel it. In addition, returning 'true' from onStartJob tells the system that you have not finished processing. You must return a "false" if you are not already doing additional work, for example. passing work to a separate thread.

 @Override public boolean onStartJob(JobParameters params) { Timber.i("on start job: " + params.getJobId()); jobFinished(params, false); return false; } 
+6
source share

It looks like you are asking why you are getting onStopJob exactly one minute after your work starts. This 1 minute timeout is defined in the code here

+3
source share

From API 26 (Oreo), setting a shorter period in excess of 15 minutes for periodic jobs will be performed in at least 15 minutes.

+2
source share

43matthew is correct, but I would like to add something else. The 2000 ms that you are talking about is a periodic interval after which the task starts again, that is, perform this task every 2000 ms, and not the interval for which the task will be executed.

0
source share

All Articles