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");
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");
相关文章推荐
- 关于在android项目中使用fragment的个人经验
- Android ViewDragHelper完全解析 自定义ViewGroup神器
- Android动画精讲一:从setTranslationX谈属性动画和view动画的区别
- Android按返回键,程序进入后台运行,不关闭程序,finishAcrivity
- Android 读书笔记---Intent 和 IntentFilter
- android数据存储之数据库
- Android下使用Properties文件保存程序设置
- Android onTouch事件传递机制
- android soap webservers 无法执行 报错 ht.call(SOAP_ACTION, envelope);解决方法
- Activity进阶知识整理
- Android自定义ListView
- android 实现button单击双击事件同时监控
- android文件存储
- Android控件之CheckBox多选框
- Android进阶之路——AIDL
- android里面隐藏控件的方法
- Android引入高速缓存的异步加载全分辨率
- Android 基础控件 TextView
- Android adb.exe程序启动不起来,如何处理
- android listview 嵌套ListView,子lv高度的问题