How to immediately kill all background processes associated with the given package in Android

One way to achieve that is to use ActivityManager.killBackgroundProcesses(String))

Sample:

1
2
ActivityManager am = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
am.killBackgroundProcesses(KillPackage);

To call this method, app needs to have KILL_BACKGROUND_PROCESSES permission. Add following entry to the Manifest:

1
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />