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