How to override back key

some time we need to override the back key of android device,suppose I have to play a audio file and when click on back button on the device then automatically the song should stop or I want to exit from application pressing the back key. that time we need to override the back button.check the simple below code.just paste in your activity class.



public boolean onKeyDown(int keyCode, KeyEvent event) {

      if(keyCode == event.KEYCODE_BACK)      {

return true;


       super.onKeyDown(keyCode, event);


       return false;



Hope you enjoy the code.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get Widget