How to disable back button in android


When user presses back button in android and you want to perform any of the action instead of exit from the app. Like you have seen in many app when user presses back button to exit an app a toast message is displayed with message “press again to exit” or a dialog is displayed to “rate the app”. Its very easy to disable back button functionality and write your own ones. All you need is to implement onBackPressed() function and Override this function, it will result like below

now just remove super.onBackPressed(); and write your own code which you want to run when user presses back button.

Please feel free to comment if you have newer techniques as well as ask questions. And, yeah! If this post helps you please do share!

Enjoy Coding and Share Knowledge




Show Buttons
Hide Buttons