Almost certainly, you will have noticed that there are two other auto-generated methods in the code of all our projects using the Basic Activity template. They are onCreateOptionsMenu
and onOptionsItemSelected
. Most Android apps have a pop up menu, so Android Studio generates one by default, including the basic code to make it work.
You can see the XML that describes the menu in res/menu/menu_main.xml
from the project explorer. The key line of XML code is this:
<item android:id="@+id/action_settings" android:orderInCategory="100" android:title="@string/action_settings" app:showAsAction="never" />
This describes a menu item with the text Settings. If you run any of the apps built with the Basic Activity template we have created so far, you can see the button as shown in the following screenshot:
If you tap the button, you can see it in action, as shown next:
So how do the onCreateOptionsMenu
and onOptionsItemSelected
methods produce...