6

I am building an Android app for RAM optimization. I can successfully get the list of running processes (and their PIDs) using this answer. However, I don't see a way to kill them or their background services by PID.

Community
  • 1
  • 1
Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118

1 Answers1

11

It turned out to be something very basic:

ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

for (RunningAppProcessInfo pid : am.getRunningAppProcesses()) {
    am.killBackgroundProcesses(pid.processName);
}
Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118