Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning when canceling ActionBar Overflow menu on Android 4.1.x

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?

like image 993
alexismorin Avatar asked Mar 02 '13 14:03

alexismorin


1 Answers

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.

like image 120
skyisle Avatar answered Oct 13 '22 21:10

skyisle