什么时候可以调用onTaskRemoved()? [英] When can onTaskRemoved() be called?

查看:841
本文介绍了什么时候可以调用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被销毁,都不会导致调用此方法.还有其他可以调用此方案的情况吗?

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.

通过按后退"按钮完成Activities并不意味着正在运行的服务和应用程序进程将被终止.除非系统终止该进程,否则服务将继续运行(如果未显式或自行停止),因此如您正确声明的那样,在完成Activities的情况下不会调用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?

否,但文档,其中用户已删除任务" 表示将应用从任务列表*中刷出.从电话的设置中停止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().

这篇关于什么时候可以调用onTaskRemoved()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆