How to Kill All Running Applications in Android

How to kill all running applications in android?

  • You can use Process.killProcess(int pid) to kill processes that have the same UID with your App.
  • You can use ActivityManager.killBackgroundProcesses(String packageName),with KILL_BACKGROUND_PROCESSES permission in your manifest(for API >= 8) or ActivityManager.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.killBackgroundProcesses or ActivityManager.restartPackage:

List<ApplicationInfo> packages;
PackageManager pm;
pm = getPackageManager();
//get a list of installed apps.
packages = pm.getInstalledApplications(0);

ActivityManager mActivityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
String myPackage = getApplicationContext().getPackageName();
for (ApplicationInfo packageInfo : packages) {
if((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM)==1)continue;
if(packageInfo.packageName.equals(myPackage)) continue;
mActivityManager.killBackgroundProcesses(packageInfo.packageName);
}

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?

How to close all running app programmatically in android?

You can only kill your own apps, e.g. the ones running in the same process or with the same userID. You can not kill others, unless the device is rooted.

Have a look at this answer though, about 'killing' background processes of apps.

How can I kill processes in Android?

  1. The message you're getting indicates that your app has crashed. You need to look at its LogCat to find out why. This is documented in the Android Developer Guide.
  2. Please state your reason for killing all background processes, because I can't think of any appropriate reason to do this. People persist in claiming that "task killers" or "app killers" improve performance, but this attitude ignores the real problem: poorly-written apps. As long as we continue to claim that task killers help, users will continue to use apps that leave unnecessary services, etc. running. Forcing users to use task killers is like dealing with a termite problem by killing one termite at a time as you see them. The real answer is to exterminate all the termites.

In short, anyone who shows you how to kill all background processes is doing you a disservice and the Android community a disservice.

Kill all recent applications in android

First get a list of RunningTaskInfo records using the following:

 [public List<ActivityManager.RunningTaskInfo> getRunningTasks (int maxNum)][1]

Reference

After that, you can use the process-ids in that list to terminate the relevant processes
using either

activityManager.killBackgroundProcess(pid);
or
android.os.Process.killProcess(pid);

depending upon whether you can kill that process. Way to kill these is detailed here.

Exit Android App - Kill all processes

int p = android.os.Process.myPid();
android.os.Process.killProcess(p);


Related Topics



Leave a reply



Submit