Android - Refresh Options Menu without calling invalidateOptionsMenu()

Michael 'Maik' Ardan picture Michael 'Maik' Ardan · Feb 14, 2013 · Viewed 20.4k times · Source

Hello Android Developers,

I have seen a lot of question regarding the update of Options Menu. However, every answer says I have to call invalidateOptionsMenu().

My question is, is there any other way of updating the Options Menu without invoking the method invalidateOptionsMenu()?

Answer

Michael 'Maik' Ardan picture Michael 'Maik' Ardan · Feb 14, 2013
@Override
    public boolean onPrepareOptionsMenu(Menu menu) {

        menu.clear(); // Clear the menu first

            /* Add the menu items */

        return super.onPrepareOptionsMenu(menu);
    }

This solved the problem on updating the OptionsMenu without invoking the invalidateOptionsMenu()