您的位置:首页 > 移动开发 > Android开发

android 应用 kill ,restart ,重启,方法

2015-10-27 19:40 495 查看
1. 通过拿到当前的进程 id ,调用 shell 命令,杀死进程。

int pid = android.os.Process.myPid();

String command = "kill -9 "+ Process.myPid();

try {

Runtime.getRuntime().exec(command);

} catch (IOException e) {

e.printStackTrace();

}

2. 调用系统的方法 杀死进程,

android.os.Process.killProcess(android.os.Process.myPid());

3 . 获得包名,重启应用

ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

am.restartPackage("com.android.nfc");

4. 调用系统的接口,退出应用。

System.exit(0);

5. 重启应用的activity

Intent k = mContext.getPackageManager().getLaunchIntentForPackage("com.android.nfc");

k.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

mContext.startActivity(k);

6. 应用重启

ActivityManager am = (ActivityManager) mContext.getSystemService(mContext.ACTIVITY_SERVICE);

am.restartPackage("com.android.nfc");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: