我已经实现了JobIntentService来执行一些后台任务,它可以在较旧的
Android设备上运行(
Android O之前).我看到意图立即处理,但在Android O设备上执行JobIntentService.onHandleWork()之前有一些延迟.我知道意图是串行处理的,但即使队列中没有处理意图,我也会看到延迟.是因为作业调度是在Android O内部处理的吗?
Here,Android文档说
“When running as a pre-O service, the act of enqueueing work will
generally start the service immediately, regardless of whether the
device is dozing or in other conditions. When running as a Job, it
will be subject to standard JobScheduler policies for a Job with a
setOverrideDeadline(long) of 0: the job will not run while the device
is dozing, it may get delayed more than a service if the device is
under strong memory pressure with lots of demand to run jobs.”
即使我的应用程序针对API 25但在OS Android O上运行,上述语句是否有效?如果是这样,是否有任何解决方法可以立即在Android O上启动服务/作业?
我目前的实施:
public class MySampleService extends JobIntentService {
private static final int JOB_ID = 1000;
public MySampleService() {
}
/**
* Convenience method for enqueuing work in to this service.
*/
public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, MySampleService.class, JOB_ID, work);
}
/**
* Interpret the incoming intent actions and handle it appropriately.
* @param workIntent
*/
@Override
protected void onHandleWork(@NonNull Intent workIntent) {
if(workIntent==null || workIntent.getAction() == null){
return;
}
/* This gets printed immediately on pre Android O devices but not otherwise*/
System.out.println("Intent Handled");
}
}