android8.0开启服务,JobIntentService无法在Android 8.0上立即启动

我已经实现了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");

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值