Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override android hardware back button functionality

Can we override hardware back button functionality. I am bit confused about this kindly help me.

like image 329
defox Avatar asked Dec 01 '22 00:12

defox


2 Answers

You can also override onBackPressed():

@Override
public void onBackPressed(){
    //Your action
}
like image 67
Jave Avatar answered Dec 04 '22 06:12

Jave


@Override public void onBackPressed(){
  //do your stuff here
}

if anything related to particular key then you can go for this:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.Any_Key_Code) {
        //your stuff here
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
like image 38
Android Killer Avatar answered Dec 04 '22 07:12

Android Killer