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.
好像只有当应用从最近的任务列表中滑出时才会调用它。按后退按钮直到任务中的所有 Activities
都被销毁不会导致调用它。还有其他可以调用的场景吗?
Pressing the back button until all Activities are destroyed in the task does not cause this to be called.
通过按后退按钮完成 Activities
并不意味着 运行 服务和应用程序进程将终止。除非系统终止进程,否则服务会保持 运行(如果未明确或自行停止),因此在完成 Activities
的情况下不会调用 Service.onTaskRemoved()
,如您正确所述。
Are there other scenarios where this could be called?
不是,而是 documentation 中描述的那个,其中 "the user has removed a task" 表示将应用程序从任务列表中滑出 *。从 phone 的设置中停止 Service
不会触发 Service.onTaskRemoved()
。
* AFAIK,在极少数情况下可能不会调用 Service.onTaskRemoved()
。
文档指出
This is called if the service is currently running and the user has removed a task that comes from the service's application.
好像只有当应用从最近的任务列表中滑出时才会调用它。按后退按钮直到任务中的所有 Activities
都被销毁不会导致调用它。还有其他可以调用的场景吗?
Pressing the back button until all Activities are destroyed in the task does not cause this to be called.
通过按后退按钮完成 Activities
并不意味着 运行 服务和应用程序进程将终止。除非系统终止进程,否则服务会保持 运行(如果未明确或自行停止),因此在完成 Activities
的情况下不会调用 Service.onTaskRemoved()
,如您正确所述。
Are there other scenarios where this could be called?
不是,而是 documentation 中描述的那个,其中 "the user has removed a task" 表示将应用程序从任务列表中滑出 *。从 phone 的设置中停止 Service
不会触发 Service.onTaskRemoved()
。
* AFAIK,在极少数情况下可能不会调用 Service.onTaskRemoved()
。