What is the difference between onCreateOptionsMenu(Menu menu) and onPrepareOptionsMenu(Menu menu)?

AndroidAndroid MenuOncreateoptionsmenu

Android Problem Overview


Explain difference between onCreateOptionsMenu(Menu menu) and onPrepareOptionsMenu(Menu menu).

Android Solutions


Solution 1 - Android

onCreateOptionsMenu() is called once.
onPrepareOptionsMenu() is called every time the menu opens.


From the onCreateOptionsMenu() documentation:

>This is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see onPrepareOptionsMenu(Menu).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJumpoView Question on Stackoverflow
Solution 1 - AndroidSamView Answer on Stackoverflow