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();