Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable "BACK" button in Android? [duplicate]

Tags:

android

back

Is their a way of disable a BACK button on my mobile? because while i'll transfer it to my mobile the BACK button is activated so that it can back the previous page. Please help me to disable BACK button while my app is running.

like image 921
chicharp Avatar asked Nov 27 '22 05:11

chicharp


2 Answers

Override the onBackPressed() of your activity

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

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

You may suppress lint's error by adding @SuppressLint("MissingSuperCall") as per Matthew Read pointed out.

like image 96
Glenn Avatar answered Dec 09 '22 16:12

Glenn


This way works for all versions of Android, and will work with libraries that may override the default functionality in their Activities (such as cocos2d-x):

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) 
{
    return (keyCode == KeyEvent.KEYCODE_BACK ? true : super.onKeyDown(keyCode, event));
}
like image 30
Phil Avatar answered Dec 09 '22 15:12

Phil