I want to kill all running applications in android. so for this task, I’ve implemented the following code. But it is not working. The app still remains running.
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningAppProcessInfo service : manager.getRunningAppProcesses()) {
Log.i("process name " , service.processName);
android.os.Process.killProcess(service.pid);
}
So where did I make a mistake in the code?
Process.killProcess(int pid)to kill processes that have the sameUIDwith your App.ActivityManager.killBackgroundProcesses(String packageName),withKILL_BACKGROUND_PROCESSESpermission in your manifest(for API >= 8) orActivityManager.restartPackage (String packageName)(for API < 8) to kill specified process,except of forground process.So if you would to kill all other processes when your program is foreground process,you would to use
ActivityManager.killBackgroundProcessesorActivityManager.restartPackage:In above snippet code,each process will be killed unless it be process of your App or system process.
References:
How to close all active applications from my Android app?
How do task killers work?