JobScheduler不重复工作 [英] JobScheduler not repeating job

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

问题描述

我正在使用JobScheduler.setPeriodic()重复我的JobIntentService.它是第一次工作,但永远不会重复.在Android 7.0上运行

I'm using a JobScheduler.setPeriodic() to repeat my JobIntentService. It works the first time but never repeats. Running on Android 7.0

ConcurrentCheck.java

ConcurrentCheck.java

int mdelaymilles  = 30000;
JobScheduler jobScheduler = (JobScheduler) mActivity.getSystemService(JOB_SCHEDULER_SERVICE);
        ComponentName componentName = new ComponentName(mActivity, ConcurrentCheckService.class);
        JobInfo jobInfo = new JobInfo.Builder(JOB_ID, componentName)
                .setPeriodic(mdelaymilles)
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .build();
        int resultCode = jobScheduler.schedule(jobInfo);
        if (resultCode == JobScheduler.RESULT_SUCCESS) {
            Log.d(LOG_TAG, "Job scheduled!");
            Intent intent = new Intent();
            intent.putExtra(LAST_POSITION, lastPosition);
            JobIntentService.enqueueWork(mActivity, ConcurrentCheckService.class, JOB_ID, intent);
        } else {
            Log.d(LOG_TAG, "Job not scheduled");
        }

推荐答案

可以安排作业的最短时间为15分钟.如果将其设置为小于15分钟的值,则该作业将使用15分钟.

The minimum period a job can be scheduled is 15 minutes. If it is set to a value less than 15 minutes, the job will use 15 minutes.

请参阅:职位信息中的MIN_PERIOD_MILLIS .

此外,请参见

查询定期计划作业允许的最小间隔.尝试在计划作业时声明一个较小的时间段会导致工作仍然是定期的,但是将与此一起运行有效期.您间隔的周期性任务将需要一些其他服务,警报管理器可能会为您工作.

Query the minimum interval allowed for periodic scheduled jobs. Attempting to declare a smaller period that this when scheduling a job will result in a job that is still periodic, but will run with this effective period. A recurring task with your interval will need some other service, possibly the Alarm Manager will work for you.

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

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