Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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));
}

This is very simple.. put this code in every activity of your android code if you wish to disable the back button for complete aplication

@Override
public void onBackPressed()
{

   //thats it
}

and you are done

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top