I don't want to get on the discussion of whether a process can be killed by the user, whether it should be done that way or not.
I just want to know how almost every Android player's phone got a 'advanced task killer
' which kills a process or how is it that the force close
(in settings) option works just fine. I have tried many ways to kill a process, but all without result. But when I see these 'advanced task killer
' I can't figure out what's wrong on my side.
You can use the killBackgroundProcesses() method of ActivityManager:
ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
am.killBackgroundProcesses(packageName);
Please, note that your app needs to own the KILL_BACKGROUND_PROCESSES permission. Thus, in the AndroidManifest.xml, you need to include:
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
Try android.os.Process:
void killMyProcess() {
android.os.Process.killProcess(android.os.Process.myPid());
}
As it implies from the method name, you can only kill your own process by using this approach.
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