什么时候可以调用 onTaskRemoved() ? [英] When can onTaskRemoved() be called?
问题描述
文档说明
如果服务当前正在运行并且用户有删除了来自服务应用程序的任务.
This is called if the service is currently running and the user has removed a task that comes from the service's application.
似乎只有在应用程序从最近的任务列表中滑出时才会调用它.按下后退按钮直到任务中的所有 Activity
都被销毁不会导致调用它.还有其他可以调用的场景吗?
It seems as if it is only called when the app is swiped away from the recent task list. Pressing the back button until all Activities
are destroyed in the task does not cause this to be called. Are there other scenarios where this could be called?
推荐答案
按下后退按钮直到任务中的所有活动都被销毁不会导致调用此方法.
Pressing the back button until all Activities are destroyed in the task does not cause this to be called.
Finish Activities
按后退按钮并不意味着正在运行的服务和应用程序进程将被终止.除非系统终止进程,否则服务将继续运行(如果没有明确或自行停止),因此在您完成 Activity
的情况下不会调用 Service.onTaskRemoved()
正确表述.
Finishing Activities
by pressing the back button doesn't mean that running services and the application process will be terminated. Services keep running (if not explicitly or self stopped) unless the system kills the process, so Service.onTaskRemoved()
isn't called in the case of finishing Activities
as you correctly stated.
还有其他可以调用的场景吗?
Are there other scenarios where this could be called?
不,但是在 documentation,其中用户删除了一个任务"意味着从任务列表中刷出应用程序*.从手机设置中停止 Service
不会触发 Service.onTaskRemoved()
.
No, but the one described in the documentation, where "the user has removed a task" means swiping the app out from the task list *. Stopping the Service
from the phone's settings does not trigger Service.onTaskRemoved()
.
* AFAIK,在极少数情况下 Service.onTaskRemoved()
可能不会被调用.
* AFAIK, in rare cases Service.onTaskRemoved()
may not be called.
这篇关于什么时候可以调用 onTaskRemoved() ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!