android l job scheduler api,Jobscheduler API android L

在开发一个使用JobScheduler API的应用时,遇到一个问题:期望只在设备充电时周期性运行服务,但即使设备未插电,服务依然每隔3秒运行。设置`setRequiresCharging(true)`似乎无效。当去掉`setPeriodic(3000)`时,充电需求的设置才起作用。开发者不确定问题出在哪里。
摘要由CSDN通过智能技术生成

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());

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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值