Android exit Dialog, AndroidMkab

How to Add Android Exit Dialog to Your Android App

  • In this Post I will show you how to add Android Exit Dialog to your Android App.
  • First of all I will explain you what is Android Exit Dialog. Dialog in Android is Popup which show a message or content to the App user and gives options through buttons Like Yes or Now, Allow or Cancel etc.
  • As a result Use if accidentally clicks back button instead of exiting the app a Popup will come and ask user for confirmation.

Android exit Dialog, How to Add Android Exit Dialog to Your Android App, AndroidMkab, AndroidMkab

  • Implementing Android Exit Dialog is Very simple to do. It takes only few minutes to add an Android exit dialog to your Android App.

Watch Video for detailed explanation of the code.



  1. Create new Android Studio Project or Open you Exiting Android Studio project.
  2. Go to your Java Package and open MainActivity.Java file and add Below code to your onBackPressed() method.
After adding above code to onBackPressed() method code look like below.


Hope you understood the method well. If you found this method useful share it and help others.

If you like Donate for My work: [paypal_donation_button]