My requirement forces me to kill another apps from my developed application.
Details: My requirement is how to kill all background running application from currently de
This will force-stop all applications including system-app
try
{
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
os.writeBytes("adb shell" + "\n");
os.flush();
Context newContext=this;
ActivityManager activityManager = (ActivityManager) newContext.getSystemService( Context.ACTIVITY_SERVICE );
List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
for(RunningAppProcessInfo appProcess : appProcesses){
if(appProcess.processName.equals("com.yourPackageName")){
}
else{
os.writeBytes("am force-stop "+appProcess.processName + "\n");
}
}
os.flush();
os.close();
suProcess.waitFor();
}
catch (IOException ex)
{
ex.getMessage();
Toast.makeText(getApplicationContext(), ex.getMessage(),Toast.LENGTH_LONG).show();
}
catch (SecurityException ex)
{
Toast.makeText(getApplicationContext(), "Can't get root access2",
Toast.LENGTH_LONG).show();
}
catch (Exception ex)
{
Toast.makeText(getApplicationContext(), "Can't get root access3",
Toast.LENGTH_LONG).show();
}
I am pretty sure this is not possible, it would be bad practice for Android to allow apps to close other apps.
The answer is in this post: Kill another process/application programmatically
Please google your question before asking it here.
We cannot actually kill all the background apps . However, we can kill our own app from recents by calling finishAndRemoveTask() which is available from lollipop.
Another Solution is we can use android:excludeFromRecents
in activity in the manifest file