Challenge: Add a Listener to the TextView .................................................................. 49
Challenge: Add a Previous Button ............................................................................. 49 Challenge: From Button to ImageButton ..................................................................... 49 3. The Activity Lifecycle ................................................................................................. 53 Logging the Activity Lifecycle .................................................................................. 54 Making log messages ...................................................................................... 54 Using LogCat ................................................................................................. 56 Rotation and the Activity Lifecycle ............................................................................ 61 Device configurations and alternative resources .................................................... 61 Saving Data Across Rotation .................................................................................... 65 Overriding onSaveInstanceState(Bundle) ............................................................. 66 The Activity Lifecycle, Revisited ............................................................................... 67 For the More Curious: Testing onSaveInstanceState(Bundle) ........................................... 69 For the More Curious: Logging Levels and Methods ..................................................... 70 4. Debugging Android Apps ............................................................................................. 73 The DDMS Perspective ............................................................................................ 74 Exceptions and Stack Traces ..................................................................................... 76 Diagnosing misbehaviors .................................................................................. 77 Logging stack traces ........................................................................................ 78 Setting breakpoints .......................................................................................... 80 Using exception breakpoints ............................................................................. 83 File Explorer .......................................................................................................... 84 Android-Specific Debugging ..................................................................................... 85 Using Android Lint ......................................................................................... 85 Issues with the R class ..................................................................................... 87 5. Your Second Activity ................................................................................................... 89 Setting Up a Second Activity .................................................................................... 90 Creating a new layout ...................................................................................... 91 Creating a new activity subclass ........................................................................ 95 Declaring activities in the manifest ..................................................................... 97 Adding a Cheat button to QuizActivity ............................................................... 98 Starting an Activity ................................................................................................. 99 Communicating with intents ............................................................................ 100 Passing Data Between Activities .............................................................................. 101 Using intent extras ........................................................................................ 102 Getting a result back from a child activity ......................................................... 104 How Android Sees Your Activities ........................................................................... 109 Challenge ............................................................................................................. 112 6. Android SDK Versions and Compatibility ...................................................................... 113 Android SDK Versions ........................................................................................... 113 Compatibility and Android Programming ................................................................... 114 Honeycomb was big ...................................................................................... 114 Minimum SDK version .................................................................................. 116 Target SDK version ....................................................................................... 116 Build SDK version ........................................................................................ 116 Adding code from later APIs safely .................................................................. 118 Using the Android Developer Documentation ............................................................. 120 Challenge: Reporting the Build Version ..................................................................... 122