0

Going off my last question Why is my options menu not showing the settings menu item correctly?, The code for everything

@Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // only add the menu when the selection fragment is showing
        if (fragments[SELECTION].isVisible()) {
            if (menu.size() == 0) {
                settings = menu.add(R.string.settings);
            }
            return true;
        } else {
            menu.clear();
            settings = null;
        }
        return false;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        if (item.equals(settings)) {
            showFragment(SETTINGS, true);
            return true;
        }
        return false;
    }

What happened was I managed to login fine, and logout fine. But when I logged out, the options menu still appeared even though menu.clear was called in onPrepareOptionsMenu(alter the menu before it's shown to the user). I managed to make it disappear but clicking the back button(destroying the activity) and recreating the activity. But why is the options menu still appearing in the first place? I don't want to burden the client with pressing back to make it disappear.

Community
  • 1
  • 1
committedandroider
  • 8,711
  • 14
  • 71
  • 126

1 Answers1

1

I think depending on the version of Android you are running. As soon as you press the logout button and do the logout routine, you should also call invalidateOptionsMenu to refresh the menu.

CChi
  • 3,054
  • 1
  • 20
  • 15
  • based on what they gave you, you don't have access to when the logout button is clicked https://developers.facebook.com/docs/android/scrumptious/authenticate – committedandroider Aug 21 '14 at 00:04
  • I found about the invalidateOptionsMenu method too but the guide(link above) made no mention of it so I am assuming the code should work fine without it – committedandroider Aug 21 '14 at 00:06
  • 1
    There must be some call back that let you know you are already logout so you have a chance to invoke invalidateOptionsMenu yourself. – CChi Aug 21 '14 at 00:08
  • yeah i found a possible location. I just feel like facebook didn't include it in the guide, you probably don't need. Could there be something else I am doing wrong? – committedandroider Aug 21 '14 at 00:10