5.5.4. Overridden Activity Method onCreateOptionsMenu

We override Activity method onCreateOptionsMenu (Fig. 5.21) to initialize Activity’s standard options menu. The system passes in the Menu object where the options will appear. In this app, we want to show the menu only when the app is running in portrait orientation. Lines 87–88 use the WindowManager to get a Display object that contains the screen’s current width and height, which changes based on the device’s orientation. If the width is less than the height, then the device is in portrait orientation. Line 89 creates a Point object to store the current width and height, then line 90 calls Display method getRealSize, which stores the screen’s width and height in the Point’s public instance ...

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.