Update – 2020-03-05
I updated the samples and snippets to include some reader feedback:
- Accounted for Master-Detail navigation in
- Provided a toast + back button confirmation alternative sample
- Updated sample: allow toggling between Master-Detail and Tabbed navigation; allow toggling between dialog and toast confirmation styles.
Ever hit the navigation bar back button when using an Android app and have it fully exit the app and drop you back on your home screen? I think all Android users have encountered this a few times. It is a frustrating and counter-productive experience. Let’s make sure your app has better UX by using a simple confirmation dialog!
Good news, this is easy to implement and should only take you a few minutes to code and test.
Create a property to check if there are pages on your navigation stack. Here’s my implementation:
OnBackPressed method in your app’s
MainActivity to intercept back navigation. Here’s a sample:
Wasn’t that easy! Let me know how this works out for your app. Check out my full Xamarin Forms Android Exit Confirmation sample on Github.