2

Hi I have implemented Android JobScheduler API which was working fine till recently but since 2/3 days there seems to be a inconsistent behaviour in jobs which are scheduled.

Here is the jobinfo builder config :

jobInfo = new JobInfo.Builder(118, new ComponentName(this, LocationJob.class)) .setBackoffCriteria(30000, JobInfo.BACKOFF_POLICY_EXPONENTIAL) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) .setExtras(persistableBundle).build();

jobScheduler.schedule(jobInfo);

Basic working is when i trigger this it used to start the Job Service class immediately but it ain't starting immediately now.

My JobService class :

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class LocationJob extends JobService {

    private static final String LOG_TAG = LocationJob.class.getSimpleName();

@Override
public boolean onStartJob(final JobParameters params) {

    try {
        /* doing some server work in another thread. */
    } catch (Exception e) {
        Log.v(LOG_TAG, e.toString() + " " + e.getMessage() + " " + e
                .getCause());
    }

    return true;
}

@Override
public boolean onStopJob(JobParameters params) {
    return false;
}
}

My JobService is not triggering immediately what sort of behaviour is this?

Vamshi Krishna
  • 87
  • 2
  • 10

1 Answers1

1

That's normal behavior. It starts it "somewhere in the (near) future". It does the same in my app. Sometimes right away, not always.

Also, your requirements, like NETWORK_TYPE_ANY, could postpone it when there is no network at the moment.

From the documentation: "Typically if you don't specify a deadline on your job, it can be run at any moment depending on the current state of the JobScheduler's internal queue, however it might be deferred as long as until the next time the device is connected to a power source." https://developer.android.com/reference/android/app/job/JobScheduler.html

Frank
  • 12,010
  • 8
  • 61
  • 78
  • I got your point but it used to trigger immediately once it is scheduled. Is there any internal queue size for the JobScheduler ? If so what is the max count so I cant schedule accordingly. And NETWORK_TYPE_ANY say whatever maybe the network connection it should schedule the jobs ASAP. That is how it should be working right. – Vamshi Krishna Aug 31 '17 at 11:28
  • Yes, you might not have network though. That it was scheduling immediately could be old version's inefficiency. It now maybe waits so it can batch some jobs from different apps or something. – Frank Aug 31 '17 at 11:32
  • 1
    Ok but I have my network connected and I'm running it on Mashmallow (6.0) – Vamshi Krishna Aug 31 '17 at 11:35
  • I don't know. As far as I know this behaviour is intended. It will run "some time in the future". – Frank Aug 31 '17 at 12:11
  • 1
    I have the JobScheduler for other jobs also they are working fine but when it comes to one of the task its getting delayed in starting the job. – Vamshi Krishna Sep 01 '17 at 06:55