如何退出android程序

来源:互联网 发布:大逃杀优化设置 编辑:程序博客网 时间:2024/05/17 02:14
今天用到了如何完全退出程序,finish()只能关掉当前的程序 最后使用的是任务管理器的方法 1 声明权限: 2 代码: ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); am.restartPackage(getPackageName()); 不建议使用System.exit(0),因为:System.exit(0); That right there will close your application out leaving nothing running in the background. However, use this wisely and don't leave files open, database handles open, etc. These things would normally be cleaned up through the "finish()" command. 还看到了另一种方法: 使用startActivityForResult(),让其返回一个关闭该程序的命令即可,一个一个ACTIVITY往前关本文转自:http://goldenrod-z4.javaeye.com/blog/724333
原创粉丝点击