I want to close all recent apps at once. I found the following code, but it only shows recent apps. I want to close all these recent apps.
Show all recent app list code: (but I don't want list i need to close all recent apps)
Class serviceManagerClass = Class.forName("android.os.ServiceManager"); Method getService = serviceManagerClass.getMethod("getService", String.class); IBinder retbinder = (IBinder) getService.invoke(serviceManagerClass, "statusbar"); Class statusBarClass = Class.forName(retbinder.getInterfaceDescriptor()); Object statusBarObject = statusBarClass.getClasses()[0].getMethod("asInterface", IBinder.class).invoke(null, new Object[] { retbinder }); Method clearAll = statusBarClass.getMethod("toggleRecentApps"); clearAll.setAccessible(true); clearAll.invoke(statusBarObject); Toast.makeText(getApplicationContext(), "All recent app closed....", Toast.LENGTH_LONG).show();
To close apps on Android, swipe up from the bottom of the screen and hold until the recent apps menu pops up (if you use gesture navigations). If you use button navigation, tap on the recent apps button. Swipe up to close individual apps or tap the Close all button to close all background apps.
Once the Developer options interface comes up, from the top-right corner, slide to set Developer options toggle button to ON. On the same interface, under the APPS section, tap to check the Don't keep activities checkbox in order to close the running activities automatically when they are not in use.
No, it's not possible to kill & remove from "Recent apps" list user's recent apps, even with Process.killProcess()
method. Read these two answers:
- Kill another application on Android?
- How to kill currently running task in android
However, what you can do is to restart the background processes of the recent apps (that's what most TaskKillers from Google Play actually do):
Add KILL_BACKGROUND_PROCESSES
user-permission into your manifest:
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
And then killBackgroundProcesses
(previously known as restartPackage
) for the process/processes you want to "kill" (even though it's not actual killing)
ActivityManager actvityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE ); List<ActivityManager.RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses(); for(ActivityManager.RunningAppProcessInfo runningProInfo:procInfos){ if (runningProInfo.processName.equals("PACKAGE_NAME_YOU_WANT_TO_KILL")) { actvityManager.killBackgroundProcesses(runningProInfo.processName); } }
As a result, "killed" apps, no longer presented in the list of running process, they are removed from memory. Apps are still in list of recent apps and you can't do anything with it - see answer clear all recent task Programmaticcally
I hope, it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With