Java tutorial
//package com.java2s; //License from project: Apache License import android.util.Log; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { private static final String CMD_FORCE_STOP_APP = "am force-stop "; public static void forceStopApp(String packageName) { String s = do_exec_with_root(CMD_FORCE_STOP_APP + packageName); Log.d("TAG", "force stop result is " + s + ".........."); } public static String do_exec_with_root(String cmd) { String s = "\n"; try { Process su_p = Runtime.getRuntime().exec("su"); DataOutputStream dataOutputStream = new DataOutputStream(su_p.getOutputStream()); dataOutputStream.writeBytes(cmd + "\n"); dataOutputStream.writeBytes("exit" + "\n"); dataOutputStream.flush(); BufferedReader in = new BufferedReader(new InputStreamReader(su_p.getInputStream())); String line = null; while ((line = in.readLine()) != null) { s += line + "\n"; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return s; } }