Mitte Mitte - 1 year ago 75
Android Question

How to force stop an Android app

How to force stop an app using Java code? I'm trying to build a memory cleaner, that can help clean out background processes.
What I mean by force stop is to make sure when you go to the app details, the FORCE STOP button is grey out.
I know there is a way to kill the process of an app, but when you go to the running list, the app is still there even after you have killed it. And I have tried a lot of similar memory cleaning apps, only one of them can totally FORCE STOP apps but it has so many useless notifications - very annoying.

When you go to

Settings -> Apps
, you can see a list of apps, click on one of them, you can get to the App info of it. There is a button named FORCE STOP. By clicking on it, the app is totally killed. I want to perform that kind of action in my app, is there any code snippet to do that?

force stop example

Answer Source

get the process ID of your application, and kill that process onDestroy() method

public void onDestroy()

    int id= android.os.Process.myPid();



and if you want to kill other apps from your activity, then this should work

You can send the signal using:

Process.sendSignal(pid, Process.SIGNAL_KILL);

To completely kill the process, it's recommended to call:


before sending the signal.

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" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download