Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable back button in android

Tags:

android

How to disable back button in android while logging out the application?

like image 945
Grace Avatar asked Jan 24 '11 08:01

Grace


People also ask

Can you disable the Back button in Android?

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.

How do I disable Home button on Android?

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.

How do I stop my back button from fluttering?

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.


2 Answers

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();    } } 
like image 196
Gopinath Avatar answered Oct 09 '22 15:10

Gopinath


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

like image 35
Rohit Sharma Avatar answered Oct 09 '22 14:10

Rohit Sharma