Efficient implemetation of AlertDialog callback in Android
for a confirmation dialog use setCancelable(true) to make the user able to cancel the dialog using the back button. This is the native way and you don't have to implement anything.

Note: in Android you are not supposed to close the application. The operating system will close it when it feels like to do so.