So I had to implement double tap to exit from app in Android using xamarin. This how it is implemented
- Create blank Android App
- Override OnBackPressed method in MainActivity.cs
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); | |
} |
- That’s it 🙂 Run the app and see the out put
Thanks. 🙂
Really helpful !
LikeLiked by 1 person
Thanks for posting! Good to know!
LikeLiked by 1 person
Reblogged this on XAM-Techie.
LikeLike