Skip to content

Instantly share code, notes, and snippets.

@junlincao
Created October 15, 2015 09:36
Show Gist options
  • Save junlincao/84d2226f946cabb86860 to your computer and use it in GitHub Desktop.
Save junlincao/84d2226f946cabb86860 to your computer and use it in GitHub Desktop.
exit app
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());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment