Disable the BACK button in Android?

Is this a way to disable the BACK button on a mobile device? because as long as I transfer it to my mobile, the BACK button is activated so that it can return to the previous page. Please help me disable the BACK button while my application is running.

+4
source share
3 answers

Override onBackPressed()your activity

@SuppressLint("MissingSuperCall")
@Override
public void onBackPressed()
{

   // super.onBackPressed(); // Comment this super call to avoid calling finish() or fragmentmanager backstack pop operation.
}

You can suppress the lint error by adding @SuppressLint("MissingSuperCall")as directed by Matthew Reed.

+20
source

Android , Activities (, cocos2d-x):

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) 
{
    return (keyCode == KeyEvent.KEYCODE_BACK ? true : super.onKeyDown(keyCode, event));
}
+6

It is very simple. Put this code in every action of your Android code if you want to disable the back button for full use

@Override
public void onBackPressed()
{

   //thats it
}

and you are done

+3
source

All Articles