How to properly override a dispatchKeyEvent in Android

I get

D/InputEventConsistencyVerifier( 2144): KeyEvent: ACTION_UP but key was not down.`
D/InputEventConsistencyVerifier( 2144): in com.android.internal.policy.impl.PhoneWindow$DecorView@41689658

warnings all over when I try to do this in my activity:

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if ((/*some boolean checks*/) && (event.getAction() == KeyEvent.ACTION_DOWN)) {
            /*some custom functions*/
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}

What is the correct way of overriding dispatchKeyEvent in the activity level? Are these warnings fine? Should I do corresponding changes in the onKeyUp and onKeyDown of my views?


Try this

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
        if (event.getAction() == KeyEvent.ACTION_UP){

         enter();

            return true;
    }}
    return super.dispatchKeyEvent(event);
};