Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getRunningAppProcesses() returns processes that were destroyed

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?

like image 750
ateiob Avatar asked Aug 07 '12 23:08

ateiob


1 Answers

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:

enter image description here

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

enter image description here

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

like image 141
Android Eve Avatar answered Nov 11 '22 16:11

Android Eve