Jobscheduler API Android L [英] Jobscheduler API android L

查看:68
本文介绍了Jobscheduler API Android L的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个使用Jobscheduler API的应用程序. 我想在设备充电时定期运行服务.这是代码.

I am making an application that makes use of the jobscheduler API. I want to run a service periodically and when the device is charged. This is the code.

JobInfo.Builder builder = new JobInfo.Builder(kJobId++, mServiceComponent);
                    builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
                    builder.setPeriodic(3000);
                    builder.setRequiresCharging(true);
                    mTestService.scheduleJob(builder.build());

现在,当我运行此程序并拔下设备的电源时,该服务仍会在3秒钟后运行.设置setRequiresCharging无效.

Now when I run this and I unplug the device, the service still runs after 3 secs. There is no effect of setting the setRequiresCharging.

当我注释掉builder.setPeriodic(3000)时,它工作得很好.我不确定我要去哪里.

When i comment out builder.setPeriodic(3000), it works perfectly fine. I am not sure as to where I am going wrong.

推荐答案

为在内部识别每个作业,框架创建了一个新的

To identify each job internally, the framework creates a new JobStatus when a new job lands on the scheduler. One of the first things JobStatus does is to check and see if your job has a periodic update interval. If it does, it uses the periodic update interval to determine the latest point in the future that a job must be run, or in other words, if it has a deadline constraint.

要考虑的工作的标准之一

One of the criteria for a job to be considered ready to be executed, it that all of its constraints have been satisfied or the deadline of a job has expired. See JobStatus.isReady for more information.

JobSchedulerService添加了几个 TimeController ,其中:

The JobSchedulerService adds several StateControllers used to track when jobs should run and when they must be stopped. One of these controllers is a TimeController, which:

为下一个即将到期的作业设置警报,并确定是否 满足了作业的最小延迟要求

sets an alarm for the next expiring job, and determines whether a job's minimum delay has been satisfied

To determine if a new alarm should be scheduled, TimeController checks if your job has any time delay or deadline constraints, which all jobs seem to be given if you set a periodic update interval.

我希望这至少可以帮助您了解为什么,尽管您受到电池限制,但仍可以继续安排工作.但是,目前我还没有解决方案可以提供简单的解决方案.

I hope that helps you at least understand why your job continues being scheduled despite your battery constraint. But I don't have a solution that can offer a straightforward fix for this at the moment.

这篇关于Jobscheduler API Android L的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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