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 the app’s preferences have changed—if so, the MainActivity’s onStart life-cycle method (Section 5.5.3) will call the QuizFragment’s methods updateGuessRows (Section 5.6.4) and updateRegions (Section 5.6.5) to reconfigure the quiz based on the user’s new settings. We set this boolean to true initially so that when the app first executes the quiz is configured using the default preferences.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset