2017-02-24 43 views
0

JobInfo.Builder有一个设置设备闲置状态的方法,但是我很困惑它到底想说什么。如何仅在设备未打瞌睡时才使用JobScheduler计划作业(甚至不包括“维护”窗口)?

setRequiresDeviceIdle (boolean requiresDeviceIdle) 

Specify that to run, the job needs the device to be in idle mode. This defaults to false. 

Idle mode is a loose definition provided by the system, which means that the device is not in use, 
and has not been in use for some time. As such, it is a good time to perform resource heavy jobs. 
Bear in mind that battery usage will still be attributed to your application, and surfaced to the user in battery stats. 

现在的布尔描述如下:

requiresDeviceIdle boolean: Whether or not the device need be within an idle maintenance window. 

基本上,我需要这份工作时,该设备不打瞌睡火,最好不要即使是在维护窗口。这项工作的目的是从网络下载东西。

将设置为false会导致它在设备不在维护窗口时运行? (实际深度睡眠状态IDLE和运行状态)

将它设置为true使其仅在维护窗口中运行并且在其他情况下不会运行?

回答

0

设置setRequiresDeviceIdle(true)将在设备打盹的维护窗口中运行预定作业。

维护窗口是打瞌睡的一段时间(空闲状态),所有累积的作业都有机会运行一段特定时间,然后设备再次打盹,然后一段时间后维护时段开始并且循环将被重复。因此,当您将true设置为setRequiresDeviceIdle()时,您的作业将仅在这些维护窗口中执行。

enter image description here

所以,如果你想你的工作,在任何时候(即使用户正在使用的设备)运行,那么设置setRequiresDeviceIdle()false

+0

我希望它当设备被激活的特别使用...只有当它活跃时。 – Kushan

+0

但是,在维护窗口中运行的作业也存在什么问题? – arjun

+0

问题是如果我将该死的标志设置为true,它只会在维护窗口中运行,并且如果仅在活动状态下为false ...那就是为什么没有mw。建议一些东西,如果你有其他 – Kushan

相关问题