Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Android P: Dropping event due to no window focus: KeyEvent

In Android P, application on start not working as expected with throwing warnings :

 W/ViewRootImpl: 
    Dropping event due to no window focus: MotionEvent { action=ACTION_DOWN, KeyCode = DPAD_DOWN} 

and

W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_UP, KeyCode = DPAD_DOWN} and its not allowing any action to performed.

Check Image for detailed warning.

Note: Same Application is working fine in Android O, but in Android P , sometimes the focus is missing in PopupMenu items and not getting back the focus until reboot the system. After using dispatchKeyEvent and setting dynamically focus to the view as v.requestFocus(); the application started working little better but still the warning is observed sometimes with feel like system hanged for a user. Check below code snippet for details:

@Override
        public boolean dispatchKeyEvent(KeyEvent event) {
            LogUtils.d(TAG, String.valueOf(event.getKeyCode()));
            this.getWindow().getDecorView().setFocusable(true);
            return super.dispatchKeyEvent(event);
        }

My Question is, how to set the missing focus dynamically to the PopupMenu and RecyclerView or how to overcome this in application running in Android P.

Please suggest, I got same type of question in stackOverflow but not a proper solution, so posting the question and waiting for all type of suggestion and answer. Thanks in advance.enter image description here

like image 764
Subhalaxmi Avatar asked Sep 06 '25 03:09

Subhalaxmi


1 Answers

In my case similar issue was caused by using onKeyDown() and KeyEvent.ACTION_DOWN everywhere, including when showing a dialog on a key press. Using onKeyUp() and KeyEvent.ACTION_UP to show dialogs and activities resolved it for me.

like image 90
vovan888 Avatar answered Sep 09 '25 20:09

vovan888