Android JobScheduler JobService无法正常工作 [英] Android JobScheduler JobService not working

查看:329
本文介绍了Android JobScheduler JobService无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我已经实现了Android JobScheduler API,该API直到最近还可以正常工作,但是自2/3天以来,在计划的作业中似乎出现了不一致的行为.

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.

这是jobinfo构建器配置:

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

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);

基本工作是当我触发此操作时,它曾经立即启动Job Service类,但现在还没有立即启动.

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

我的JobService类:

@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;
}
}

我的JobService不会立即触发这种行为吗?

推荐答案

这是正常行为.它开始于(在不久的将来)某个地方".它在我的应用程序中也一样.有时候,并非总是如此.

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

此外,当当前没有网络时,您的要求(例如NETWORK_TYPE_ANY)也可以将其推迟.

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

从文档中:通常,如果您不指定任务的截止日期,则可以根据JobScheduler内部队列的当前状态随时运行该截止日期,但是可以将其推迟到下一个设备连接到电源的时间." https://developer.android.com/reference/android/app/job/JobScheduler.html

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

这篇关于Android JobScheduler JobService无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆