终于解决了 焦点不在ActivityGroup而在childActivity中时,捕获Back事件的问题。
正确的方法如下:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
System.out.println(KeyEvent.KEYCODE_BACK+"--------------------"+event.getKeyCode()+"---------------------"+event.getAction());
if(event.getKeyCode()==KeyEvent.KEYCODE_BACK && event.getAction()==KeyEvent.ACTION_DOWN){
exitDialog();
return true;
}
return super.dispatchKeyEvent(event);
}
正确的方法如下:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
System.out.println(KeyEvent.KEYCODE_BACK+"--------------------"+event.getKeyCode()+"---------------------"+event.getAction());
if(event.getKeyCode()==KeyEvent.KEYCODE_BACK && event.getAction()==KeyEvent.ACTION_DOWN){
exitDialog();
return true;
}
return super.dispatchKeyEvent(event);
}