运行android程序时显示stop,Android系统.应用程序关闭时WorkManager是否正在运行?

我想安排每晚数据库更新.所以我使用新的Android WorkManager.我的理解是,一旦安排它将始终独立于应用程序的生命周期在后台运行.

是对的吗?我的第一次测试显示Work只在应用程序运行时执行.

val locationWork = PeriodicWorkRequest.Builder(UpdateDatabaseWorker::class.java, 24, TimeUnit.HOURS)

.addTag("DATABASE_UPDATE_SERVICE")

.build()

WorkManager.getInstance().enqueue(locationWork)

解决方法:

根据WorkManager bugtracker上报告的各种问题,他们的文档并不完全准确地说明了在这种边缘情况下WorkManager的确切行为.

On certain devices, apps are force stopped when the app is cleared from task manager, so that part is expected. … 07001

Unfortunately, some devices implement killing the app from the recents menu as a force stop. Stock Android does not do this. When an app is force stopped, it cannot execute jobs, receive alarms or broadcasts, etc. So unfortunately, it’s infeasible for us to address it – the problem lies in the OS and there is no workaround. 07002

The only issue that we have come across is the case where some Chinese OEMs treat swipe to dismiss from Recents as a force stop. When that happens, WorkManager will reschedule all pending jobs, next time the app starts up. Given that this is a CDD violation, there is not much more that WorkManager can do given its a client library. 07003

To add to this, if a device manufacturer has decided to modify stock Android to force-stop the app, WorkManager will stop working (as will JobScheduler, alarms, broadcast receivers, etc.). There is no way to work around this. Some device manufacturers do this, unfortunately, so in those cases WorkManager will stop working until the next time the app is launched. 07003

通过对具有库存android的Pixel 2 XL进行强烈的OneTimeWorkRequest(无约束)测试,行为如下:

>任务经理关闭:

>工作继续(稍后)

>重启设备(正常运行):

>重启完成后继续工作

>应用信息“强制停止”:

>工作停止,只有在再次启动应用程序时才会继续

>重启设备(工作是“强制停止”):

>在应用再次启动之前,工作不会继续

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值