重写dispatchKeyEvent方法 按返回键back 执行两次的解决方法

@Override
	public boolean dispatchKeyEvent(KeyEvent event) {
		if(event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() != KeyEvent.ACTION_UP) {//不响应按键抬起时的动作 
			//TODO 代码  
			System.out.println("Back pressed. event.getKeyCode() => " + event.getKeyCode() + ", event.getKeyCode() => " + event.getAction());
            return true;//注意这儿返回值为true时该事件将不会继续往下传递,false时反之。根据程序的需要调整
		}
		return super.dispatchKeyEvent(event);
	}

你可能感兴趣的:(UP)