Working with OptionMenus
Each activity can have it’s own menu defined. Here’s a quick info on getting your menu up and running.
OptionsMenu event cycle
- onCreateOptionsMenu(Menu menu) - The point at which you should add all the items you need into the menu. Call the super inherited method to have the menu populated with the default items.
- onPrepareOptionsMenu(Menu menu) - The point at which you can enable / disable and dynamic content, etc to respond to the state of the activity.
- onOptionsMenuClosed(Menu menu) - called when the menu is closed.
When items are added to the Menu in OnCreateOptionsMenu you can either pass a runnable in at that point to associate with the menu item, or alternatively you can override the onOptionsItemSelected to provide a central place where you can call out to methods that the menu items invoke.
Other OptionsMenu methods
- openOptionsMenu() - Opens the OptionsMenu
- closeOptionsMenu() - Closes the OptionsMenu if open.
