According to the Android menu documentation and a similar question, onPrepareOptionsMenu
should be used to update menus dynamically. For Android 3.0 and higher, the documentation says:
When an event occurs and you want to perform a menu update, you must call
invalidateOptionsMenu()
to request that the system callonPrepareOptionsMenu()
However, when calling invalidateOptionsMenu()
, the system calls both, onCreateOptionsMenu()
and onPrepareOptionsMenu()
. Resuming the activity also either calls both methods (if it was stopped in background) or none.
To me, this sounds like the differentiation between the two methods is obsolete. Is there any situation in which Android only calls onPrepareOptionsMenu()
but not onCreateOptionsMenu()
? Additionally, is there a way to manually request that Android only calls onPrepareOptionsMenu()
, like it is implied in the documentation (cited below)?
[
onCreateOptionsMenu()
] is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see onPrepareOptionsMenu(Menu).
Thank you very much!