how to disable back button in android

Sam picture Sam · Apr 15, 2011 · Viewed 62.9k times · Source

i am making swap application... i want to disable back button. so i use this code... and passed intent in to it..

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // do something on back.
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

but while running when i press back button on emulator it updates activity but when i repress back button it switch to the home page of an emulator.. please suggest is their any other method

Answer

Saurabh Pareek picture Saurabh Pareek · Apr 15, 2011
@Override
public void onBackPressed() {
    // do nothing.
}