Android杀死整个APP方法

来源:互联网 发布:安卓手机数据恢复精灵 编辑:程序博客网 时间:2024/05/20 11:26

public static void killProcess(Context mAct) {

String packageName = mAct.getPackageName();

String processId = "";

try {

Runtime r = Runtime.getRuntime();

Process p = r.exec("ps");

BufferedReader br = new BufferedReader(new InputStreamReader(p

.getInputStream()));

String inline;

while ((inline = br.readLine()) != null) {

if (inline.contains(packageName)) {

break;

}

}

br.close();

StringTokenizer processInfoTokenizer = new StringTokenizer(inline);

int count = 0;

while (processInfoTokenizer.hasMoreTokens()) {

count++;

processId = processInfoTokenizer.nextToken();

if (count == 2) {

break;

}

}

r.exec("kill -15 " + processId);

} catch (IOException ex) {

}

}