Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double callbacks onMenuOpened/onPanelClosed on each menu button press

In my Android app I want to collect statistics on when (how often) the overflow (three dots) action bar menu is opened and closed (without an item being selected). For this task I have overriden onMenuOpened and onPanelClosed methods within an Activity. However, on all the devices (Android 4.4, 4.2; Samsung and HTC) I've tried this so far these methods are triggered twice, each time the menu is opened and closed. Is this a bug? Is there another way to monitor this menu opening and closing?

like image 671
Leo K Avatar asked May 25 '14 20:05

Leo K


1 Answers

you can try this...i have tested it ....it works perfect....

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    Activity activity = getActivity();
    activity.getActionBar().addOnMenuVisibilityListener(new OnMenuVisibilityListener() {
    @Override
        public void onMenuVisibilityChanged(boolean isVisible) {
            // TODO Auto-generated method stub
            //you can check the isVisible boolean to check
            // if the overFlowMenu is visible or not
        }
    });
like image 126
the_D Avatar answered Oct 04 '22 13:10

the_D