Could anyone explain the purpose of this method?
onCreateOptionsMenu
I've already looked at a number of sites (in the Android documentation as well), but it's still unclear what the purpose of this method is.
Could anyone explain the purpose of this method?
onCreateOptionsMenu
I've already looked at a number of sites (in the Android documentation as well), but it's still unclear what the purpose of this method is.
This is one of the public methods available from Activity that can be overwritten. The purpose of it is to simply create menus of options of an Activity by inflating an XML (Menu).
These are the menus that are usually at the top right-hand side of the application.
An example WhatsApp option menu:
Notes:
- Thismethodiscalledonlyonceafterthe
onStart()
methodintheActivitylifecycle.Tomakeitdynamictochangeevent-basedmenuitemsduringtheActivitylifecycle,youcanusetheonPrepareOptionsMenu()
- Themenudisplaymayvaryinandroidversions
ButwhyusetheAndroidmenuAPIs?
Althoughyouarefreetocreatesomethingfromscratch,usingtheavailableAPIsisrecommendedaswellasbeingmucheasiertocreateandmaintain,theuserisalreadyfamiliarwiththistypeofnavigation.
Related:
onOptionsItemSelected()
Clicklistmethodintheoptionsmenu.Withthismethodyoucanknowwhichmenuitemhasbeenclickedandperformspecificactions.
Moreabout: