Android JobScheduler JobService not working

旧时模样 提交于 2019-12-11 06:14:27

问题


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?


回答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



来源:https://stackoverflow.com/questions/45980135/android-jobscheduler-jobservice-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!