服务和 PeriodicWorkRequest() 之间的区别
Difference between Service and PeriodicWorkRequest()
我必须处理一个项目,我必须每 15 分钟上传一次用户的位置。为此,我搜索了很多并找到 Recurring work with PeriodicWorkRequest. But the problem is that the WorkManager might not work when the app is closed/killed per the answer given 。然后我在 android 中找到了有关服务的信息。
所以我想知道如果我想每 15 分钟发送一次用户的位置,即使应用程序已被终止,那么如何处理这个问题?
如果应用程序被强制停止,OS 将取消与该应用程序相关的所有作业。这不仅仅是 WorkManager 的问题。 OS 将强制停止解释为用户对 OS 的请求,他们不希望此应用程序再 运行。
即使你用了JobScheduler或者一个Service,应用也没了。但强制停止应该由用户决定。
一些 OEM 过去对 Android OS 进行了一些更改,因此从启动器中滑出应用程序会被解释为强制停止,所有负面影响都按计划进行职位。这就是问题开始的地方。
WorkManager 在这种情况下已经实施了一些缓解措施,但如果应用程序被强制停止,则应用程序将无法执行任何操作,直到用户再次启动它。
如果特定 OEM 有问题,请open an issue on the Android issuetracker as this maybe a CDD violation. Google can contact the OEM and request that they fix the ROM. This is going to take time, in the meanwhile, you can take a look at sites like don't kill my app to understand what are the constraints on a specific device and use a library like autostarter帮助用户找到正确的设置。
我必须处理一个项目,我必须每 15 分钟上传一次用户的位置。为此,我搜索了很多并找到 Recurring work with PeriodicWorkRequest. But the problem is that the WorkManager might not work when the app is closed/killed per the answer given
所以我想知道如果我想每 15 分钟发送一次用户的位置,即使应用程序已被终止,那么如何处理这个问题?
如果应用程序被强制停止,OS 将取消与该应用程序相关的所有作业。这不仅仅是 WorkManager 的问题。 OS 将强制停止解释为用户对 OS 的请求,他们不希望此应用程序再 运行。
即使你用了JobScheduler或者一个Service,应用也没了。但强制停止应该由用户决定。
一些 OEM 过去对 Android OS 进行了一些更改,因此从启动器中滑出应用程序会被解释为强制停止,所有负面影响都按计划进行职位。这就是问题开始的地方。
WorkManager 在这种情况下已经实施了一些缓解措施,但如果应用程序被强制停止,则应用程序将无法执行任何操作,直到用户再次启动它。
如果特定 OEM 有问题,请open an issue on the Android issuetracker as this maybe a CDD violation. Google can contact the OEM and request that they fix the ROM. This is going to take time, in the meanwhile, you can take a look at sites like don't kill my app to understand what are the constraints on a specific device and use a library like autostarter帮助用户找到正确的设置。