Some other overridden functions
You may have noticed that there are two other autogenerated functions in the code of all our projects using the Basic Activity template. They are onCreateOptionsMenu
and onOptionsItemSelected
. Many Android apps have a pop-up menu, so Android Studio generates one by default when using the Basic Activity template, including the outline of the 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 lines of XML code are as follows:
<item android:id="@+id/action_settings" android:orderInCategory="100" android:title="@string/action_settings" app:showAsAction="never" />
This describes a menu item with the Settings text. If you run any of our apps built with the Basic Activity template, you will see the button as shown in the following screenshot:
If you tap the button, you can see it in action as follows:
So, how do the onCreateOptionsMenu
and onOptionsItemSelected
functions...