5.5.1. package Statement, import Statements and Fields

Figure 5.18 shows the MainActivity package statement, import statements and fields. Lines 6–21 import the various Java and Android classes and interfaces that the app uses. We’ve highlighted the new import statements, and we discuss the corresponding classes and interfaces in Section 5.3 and as they’re encountered in Sections 5.5.2––5.5.6.

Lines 26–27 define constants for the preference keys you created in Section 5.4.10. You’ll use these to access the corresponding preference values. The boolean variable phoneDevice (line 29) specifies whether the app is running on a phone—if so, the app will allow only portrait orientation. The boolean variable preferencesChanged (line 30) specifies whether ...

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.