-1

I am new to android and i was actually try to use onBackPressed using if method.

For example:

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

if( pressed back button... ){

// action
}

}

Overriding onBackPressed method didnt help me at all

1 Answers1

1

Try something like this:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // your after back press code
        return true;
    }

    return super.onKeyDown(keyCode, event);
}
Krupa Patel
  • 3,309
  • 3
  • 23
  • 28