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