2015年11月10日 星期二

Handle back key event

Reference:

http://stackoverflow.com/questions/5312334/how-to-handle-back-button-in-activity

Code snippet:

For API level 5

@Override
public void onBackPressed() {
    // your code.
}

For older then API 5 use this:

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

    return super.onKeyDown(keyCode, event);
}

沒有留言: