How to disable back button in android while logging out the application?
Please navigate to Android->Advanced Restrictions->Display Settings. Uncheck the 'Hide navigation bar' option. This will disable the on-screen buttons: back, home and recent apps.
Navigate to Android > Restrictions > Basic and click on Configure. Under Allow Device Functionality, you'll have the options to disable Home/Power button. Home Button-Uncheck this option to restrict users from using the Home Button. Power Off-Uncheck this option to restrict users from turning their devices off.
To disable back button in Flutter, you can use the WillPopScope widget. The WillPopScope widget helps you get a callback whenever the back button is pressed. Inside the callback, if you return true the screen will be popped and if you return false, you have simply disabled the back button.
Override the onBackPressed method and do nothing if you meant to handle the back button on the device.
@Override public void onBackPressed() { if (shouldAllowBack()) { super.onBackPressed(); } else { doSomething(); } }
If looking for a higher api level 2.0 and above this will work great
@Override public void onBackPressed() { // Do Here what ever you want do on back press; }
If looking for android api level upto 1.6.
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR return true; } return super.onKeyDown(keyCode, event); }
Write above code in your Activity to prevent back button pressed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With