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

巧了我就是萌 提交于 2019-12-21 21:40:04

问题


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.


回答1:


I have the same problem on android p when show PopupWindow

and i solved it but by View.post() like this:

getView().post(new Runnable()
{
    @Override
    public void run()
    {
        // show popup window
    }
});

hope can help you




回答2:


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.



来源:https://stackoverflow.com/questions/54702989/in-android-p-dropping-event-due-to-no-window-focus-keyevent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!