当前位置:   article > 正文

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

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

>任务经理关闭:

>工作继续(稍后)

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

>重启完成后继续工作

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

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

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/945147
推荐阅读
相关标签
  

闽ICP备14008679号