Warning when canceling ActionBar Overflow menu on Android 4.1.x

穿精又带淫゛_ 提交于 2019-11-29 02:16:52

问题


This is the warning I'm getting:

03-02 14:38:43.980: W/InputEventReceiver(3961): Attempted to finish an input event but the input event receiver has already been disposed.

The menu I have was generated from a regular res/menu/activity_menu.xml file. I'm handling the events exactly as detailed on http://developer.android.com/guide/topics/ui/menus.html#options-menu

When I click the vertical three dots to open the overflow menu and cancel out of it, I get that warning. There seems to be little knowledge of how to catch its trigger. Any ideas?


回答1:


This is not related with your work.

Overflow menu is implemented by PopupWindow. When user touch to close PopupWindow, ACTION_DOWN event queued to app's Message queue. Then it is delivered to View through ViewPostImeInputStage class and finally ViewPostImeInputStage send this input event to PopupWindow's onTouchEvent listener.

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        final int x = (int) event.getX();
        final int y = (int) event.getY();

        if ((event.getAction() == MotionEvent.ACTION_DOWN)
                && ((x < 0) || (x >= getWidth()) || (y < 0) || (y >= getHeight()))) {
            dismiss();
            return true;
        } else if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
            dismiss();
            return true;
        } else {
            return super.onTouchEvent(event);
        }
    }

dissmiss() try to close PopupWindow and PopupWindow::onDetachedWindow call WindowInputEventReceiver::dispose() first.

And then ViewPostImeInputStage call WindowInputEventReceiver::finishInputEvent to finish that ACTION_DOWN event. However WindowInputEventReceiver instance is already disposed so it throw warning messages.

You can debug it by breakpoint. open InputEventReceiver.java(need android source code at framework/base/) and set breakpoint at dispose method.



来源:https://stackoverflow.com/questions/15175352/warning-when-canceling-actionbar-overflow-menu-on-android-4-1-x

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