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?
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With