They are two separate things. The names tell you. R.layout.activity_main
is your layout, R.menu.activity_main
is for your menu.
setContentView()
sets the layout for the Activity. It includes Buttons, TextViews, etc.
onCreateOptionsMenu()
makes the menu that you see when you press the menu key or it populates the ActionBar on Android 3.0+.
They do two completetly separate things. setContentView()
is often needed (unless you have an empty Activity
), onCreateOptionsMenu()
is optional, depending on if you need to show more options.