ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Android系统.应用程序关闭时WorkManager是否正在运行?

2019-09-10 13:28:35  阅读:780  来源: 互联网

标签:android android-jetpack android-service 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(无约束)测试,行为如下:

>任务经理关闭:

>工作继续(稍后)

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

>重启完成后继续工作

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

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

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

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

标签:android,android-jetpack,android-service,android-workmanager
来源: https://codeday.me/bug/20190910/1798716.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有