[英]onTaskRemoved() doesn't work on Android 8.0 Oreo API level 26
On device with Android Oreo 8.0 (API level 26) JobService.onTaskRemoved()
isn't called 在装有Android Oreo 8.0(API级别26)的
JobService.onTaskRemoved()
上,未调用JobService.onTaskRemoved()
Code used which stopped working: 使用的代码停止工作:
class TaskRemovalWatcherService: JobIntentService() {
...
override fun onTaskRemoved(rootIntent: Intent?) {
//not called on Android Oreo
super.onTaskRemoved(rootIntent);
onAppRemovedFromRecentApps()
}
}
When App-Task is removed from recent apps I need to 从最近的应用程序中删除应用程序任务时,我需要
if AppTasks.size = 2 and 1 task is removed from recent apps, then process is NOT killed, because 2nd AppTask still in memory. 如果AppTasks.size = 2并且从最近的应用程序中删除了1个任务,则不会终止进程,因为第2个AppTask仍在内存中。
Update: 更新:
JobIntentService.enqueueWork
then right after JobIntentService.onHandleWork()
JobIntentService.onDestroy()
is called JobIntentService.enqueueWork
则在JobIntentService.onHandleWork()
JobIntentService.onDestroy()
JobService.schedule()
throws IllegalArgumentException
when schadule job without constraints. JobService.schedule()
作业无约束时,使用JobService.schedule()
会抛出IllegalArgumentException
。 PS The idea of checking each X seconds isTaskWasRemoved seems not a good one. PS 每隔X秒检查一次的想法isTaskWasRemoved似乎不是一个好主意。
您可以覆盖JobService#onStop()
,然后创建一条消息并将其传递给其他服务,当该服务收到该消息时,您可以清理它的工作并杀死它。
The expected behavior of START_STICKY
might have changed due to custom implementation by device manufacturer or due to new implementation in android Oreo START_STICKY
的预期行为可能由于设备制造商的自定义实现或android Oreo中的新实现而发生了变化
You can use JobScheduler
to monitor a service lifecycle after regular interval. 您可以使用
JobScheduler
定期监控服务生命周期。 If service is destroyed, then you can perform your task in onDestroy()
method just before service is actually being destroyed. 如果服务被销毁,则可以在服务真正被销毁之前使用
onDestroy()
方法执行任务。
This will remove your dependency from onTaskremoved()
method. 这将从
onTaskremoved()
方法中删除您的依赖onTaskremoved()
。
Please refer below question with similar problem onTaskRemoved() not getting called when Home press & kill the app 请按以下问题,并在按下Home键并杀死应用程序时未调用onTaskRemoved()类似问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.