Search code examples
androidandroid-menuandroid-2.3-gingerbread

onPrepareOptionsMenu only called once on Android 2.3


I am putting some code to dynamically control the visibility of some menu items in Activity.onPrepareOptionsMenu. It works perfect on android 5.0. However, when I tried it on android 2.3, I found onPrepareOptionsMenu is called only once during the life time of the entire app. And the trouble with that invalidateOptionsMenu is not available on android 2.3 either.

Any idea how to solve this problem?


Solution

  • you should be able to use supportInvalidateOptionsMenu(). It is the backward compatible method for invalidateOptionsMenu(). Here you can find the documentation