Android 监听返回等按键事件
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
//执行的代码
break;
}
return super.onKeyUp(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
long secondTime = System.currentTimeMillis();
if (secondTime - firstTime > 1000) {
//执行的代码
return true;
} else {
//执行的代码
}
break;
}
return super.onKeyUp(keyCode, event);
}