getRunningAppProcesses() returns processes that were destroyed

北慕城南 提交于 2019-12-22 06:56:53

问题


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);
}

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.

Why?

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

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

Is killProcess() my only recourse?


回答1:


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

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:

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

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

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().



来源:https://stackoverflow.com/questions/11855735/getrunningappprocesses-returns-processes-that-were-destroyed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!