Created
March 7, 2014 09:38
-
-
Save Kursulla/9408501 to your computer and use it in GitHub Desktop.
Twice Back Button Exit [Android]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Define as Actviity properties | |
private long backPressTime; | |
private static final int DOUBLE_BACK_TIME_LIMIT = 800; | |
//Define method that will perform the "magic" | |
private void doubleBackPressTrigger() { | |
if (backPressTime + DOUBLE_BACK_TIME_LIMIT > System.currentTimeMillis()) { | |
super.onBackPressed(); | |
}else { | |
Toast.makeText(getBaseContext(), "Press \"Back\" twice to get out of the application!", Toast.LENGTH_SHORT).show(); | |
} | |
backPressTime = System.currentTimeMillis(); | |
} | |
//Put in your activity you want to be enabled with "double back exit" | |
@Override | |
public void onBackPressed() { | |
doubleBackPressTrigger(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment