Doubt about the onCreateOptionsMenu method

0

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.

    
asked by anonymous 14.12.2018 / 13:58

1 answer

2

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:

  
  • ThismethodiscalledonlyonceaftertheonStart()methodintheActivitylifecycle.Tomakeitdynamictochangeevent-basedmenuitemsduringtheActivitylifecycle,youcanusetheonPrepareOptionsMenu()
  •   
  • Themenudisplaymayvaryinandroidversions
  •   

ButwhyusetheAndroidmenuAPIs?

Althoughyouarefreetocreatesomethingfromscratch,usingtheavailableAPIsisrecommendedaswellasbeingmucheasiertocreateandmaintain,theuserisalreadyfamiliarwiththistypeofnavigation.

Related:

onOptionsItemSelected()

Clicklistmethodintheoptionsmenu.Withthismethodyoucanknowwhichmenuitemhasbeenclickedandperformspecificactions.

Moreabout:

14.12.2018 / 15:05