Android中完全退出应用程序

来源:互联网 发布:格兰杰詹姆斯数据 编辑:程序博客网 时间:2024/05/01 05:53

直接上代码吧,不管你是在一个还是多个activity里面直接使用下面这个方法,则可以完全的退出户整个程序。

int currentVersion = android.os.Build.VERSION.SDK_INT;                if (currentVersion > android.os.Build.VERSION_CODES.ECLAIR_MR1) {                    Intent startMain = new Intent(Intent.ACTION_MAIN);                    startMain.addCategory(Intent.CATEGORY_HOME);                    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                    startActivity(startMain);                    System.exit(0);                } else {// android2.1                    ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);                    am.restartPackage(getPackageName());                }



原创粉丝点击