getRunningAppProcesses()返回被摧毁的过程 [英] getRunningAppProcesses() returns processes that were destroyed

查看:748
本文介绍了getRunningAppProcesses()返回被摧毁的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的代码片段,以检查是否我应用程序完成() ED确实不再运行:

I am using the following snippet to check whether applications that I finish()ed are indeed no longer running:

ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> procList = am.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo proc : procList)
    Log.d(TAG, proc.processName);
}

要我失望的是,一些应用程序I 完成() ED(在他们Activity.onCreate(),他们有机会推出什么,甚至之前),仍列出。

To my dismay, some applications that I finish()ed (in their Activity.onCreate(), even before they had a chance to launch anything), are still listed there.

为什么?

LogCat中显示,这些应用程序的的onDestroy() 绝对调用。

LogCat shows that these applications' onDestroy() was definitely called.

怎样才能真正从中删除列表中的应用程序?

What does it take to truly remove an application from that list?

killProcess()我唯一的办法?

推荐答案

这是混淆了很多的领域,如可在看到<一href="http://stackoverflow.com/questions/6108830/android-does-ondestroy-or-finish-actually-kill-the-activity">this其他线程。

This is an area of confusion for many, as can be seen in this other thread.

事实上,即便从一个受人尊敬的来源这本书如奥赖利可以通过迷惑事项这表明的打掉的状态可能意味着封杀,它可以到达任何的onDestroy()工艺杀死

In fact, even this book from a respected source such as O'Reilly can confuse matters by suggesting that the Destroyed state can mean "killed" and that it can be reached from either onDestroy() or process killed:

恕我直言,这O'Reilly的状态图是有缺陷的,并不能反映该系统的全部行为的官方图的作用:

IMHO, that O'Reilly state diagram is flawed and doesn't reflect the full behavior of the system as the "official" diagram does:

这个图上分析,我们可以得出这样的结论的onDestroy()永远不会自动导致的应用程序杀死的。我相信这回答你的第一个问题。

Analyzing this diagram, one can conclude that onDestroy() never automatically leads to App process killed. I believe this answers your first question.

至于你的第二个问题,答案是:如果你真的想彻底杀死你的应用程序的进程(?为什么你会想这样做),那么你唯一的办法就是<一个href="http://developer.android.com/reference/android/os/Process.html#killProcess%28int%29">killProcess().

As for you second question, the answer is yes: If you really want to totally kill your application's process (why would you want to do that?), then your only recourse is killProcess().

这篇关于getRunningAppProcesses()返回被摧毁的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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