Created
March 15, 2018 13:05
-
-
Save jeevan-vj/040ddc50b82b12c6f4c7fc126cb2471d to your computer and use it in GitHub Desktop.
Double tap to exit xamarin 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
private bool doubleBackToExitPressedOnce = false; | |
public override void OnBackPressed() | |
{ | |
if (doubleBackToExitPressedOnce) | |
{ | |
base.OnBackPressed(); | |
Java.Lang.JavaSystem.Exit(0); | |
return; | |
} | |
this.doubleBackToExitPressedOnce = true; | |
Toast.MakeText(this, "Double tap to exit", ToastLength.Short).Show(); | |
new Handler().PostDelayed(() => | |
{ | |
doubleBackToExitPressedOnce = false; | |
}, 2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment