Articles‎ > ‎Android Articles‎ > ‎

Control Back Button In Android

posted Jan 27, 2011, 2:17 AM by Thiyagaraaj Mp   [ updated Aug 20, 2011, 4:36 AM by Thiyagaraaj M ]

Control default back button in Android
Simple Example Code

Add Override Function:

    onKeyDown(....)

Back Button Key Code:

    KeyEvent.KEYCODE_BACK

Example Code:

 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
     if (keyCode == KeyEvent.KEYCODE_BACK) {
         Pop("Back Button");
         Intent intent = new Intent();
         setResult(RESULT_OK, intent);
         finish();
         return true;
     }
     return super.onKeyDown(keyCode, event);
 }

Comments