5.5.5. Overridden Activity Method onOptionsItemSelected

Method onOptionsItemSelected (Fig. 5.22) is called when a menu item is selected. In this app, the default menu provided by the IDE when you created the project contains only the Settings menu item, so if this method is called, the user selected Settings. Line 106 creates an explicit Intent for launching the SettingsActivity. The Intent constructor used here receives the Context from which the Activity will be launched and the class representing the Activity to launch (SettingsActivity.class). We then pass this Intent to the inherited Activity method startActivity to launch the Activity.

102      // displays SettingsActivity when running on a phone103      @Override ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.