Android Programming: The Big Nerd Ranch Guide, 5th Edition

Book description

Android Programming: The Big Nerd Ranch Guide is an introductory Android book for programmers with Kotlin experience.

Based on Big Nerd Ranch's popular Android Bootcamp, this guide will lead you through the wilderness using hands-on example apps combined with clear explanations of key concepts and APIs. This book focuses on practical techniques for developing apps in Kotlin compatible with Android 5.0 (Lollipop) through Android 8.1 (Oreo) and beyond.

Write and run code every step of the way, using Android Studio to create apps that integrate with other apps, download and display pictures from the web, play sounds, and more. Each chapter and app has been designed and tested to provide the knowledge and experience you need to get started in Android development.

The Android team is constantly improving and updating Android Studio and other tools. As a result, some of the instructions provided in the book have changed. You can find an addendum addressing breaking changes at: https://github.com/bignerdranch/AndroidCourseResources/raw/master/4thEdition/Errata/4eAddendum.pdf.

..

Table of contents

  1. Title Page
  2. Dedication
  3. Acknowledgments
  4. Table of Contents
  5. Learning Android
    1. Prerequisites
    2. What’s New in the Fifth Edition?
    3. Kotlin vs Java
    4. How to Use This Book
    5. How This Book Is Organized
      1. Challenges
      2. Are you more curious?
    6. Typographical Conventions
    7. Using an eBook
    8. Android Versions
  6. The Necessary Tools
    1. Downloading and Installing Android Studio
    2. Downloading Earlier SDK Versions
    3. A Hardware Device
  7. 1. Your First Android Application
    1. App Basics
    2. Creating an Android Project
    3. Navigating in Android Studio
    4. Laying Out the UI
      1. The view hierarchy
      2. View attributes
        1. android:layout_width and android:layout_height
        2. android:orientation
        3. android:text
      3. Creating string resources
      4. Previewing the layout
    5. From Layout XML to View Objects
      1. Resources and resource IDs
    6. Wiring Up Views
      1. Getting references to views
      2. Setting listeners
    7. Making Toasts
    8. Running on the Emulator
    9. For the More Curious: The Android Build Process
      1. Android build tools
    10. Challenges
    11. Challenge: Switching Your Toast for a Snackbar
  8. 2. Interactive User Interfaces
    1. Creating a New Class
    2. Updating the Layout
    3. Wiring Up the User Interface
    4. Adding an Icon
      1. Referencing resources in XML
    5. Screen Pixel Densities
    6. Running on a Device
    7. Challenge: Add a Listener to the TextView
    8. Challenge: Add a Previous Button
  9. 3. The Activity Lifecycle
    1. Rotating GeoQuiz
    2. Activity States and Lifecycle Callbacks
    3. Logging the Activity Lifecycle
      1. Making log messages
      2. Using Logcat
    4. Exploring How the Activity Lifecycle Responds to User Actions
      1. Temporarily leaving an activity
      2. Finishing an activity
      3. Rotating an activity
    5. Device Configuration Changes and the Activity Lifecycle
    6. For the More Curious: Creating a Landscape Layout
    7. For the More Curious: UI Updates and Multi-Window Mode
    8. For the More Curious: Log Levels
    9. Challenge: Preventing Repeat Answers
    10. Challenge: Graded Quiz
  10. 4. Persisting UI State
    1. Including the ViewModel Dependency
    2. Adding a ViewModel
      1. ViewModel lifecycle
      2. Add data to your ViewModel
    3. Saving Data Across Process Death
    4. For the More Curious: Jetpack, AndroidX, and Architecture Components
    5. For the More Curious: Avoiding a Half-Baked Solution
    6. For the More Curious: Activity and Instance State
  11. 5. Debugging Android Apps
    1. Exceptions and Stack Traces
      1. Diagnosing misbehaviors
      2. Logging stack traces
      3. Setting breakpoints
    2. Android-Specific Debugging
      1. Using Android Lint
      2. Build issues
    3. Challenge: Using Conditional Breakpoints
    4. Challenge: Exploring the Layout Inspector
    5. Challenge: Exploring the Profiler
  12. 6. Testing
    1. Two Types of Tests
    2. JVM Tests
    3. Instrumented Tests with Espresso and ActivityScenario
    4. Challenge: Asserting Yourself
  13. 7. Your Second Activity
    1. Setting Up a Second Activity
      1. Creating a new activity
      2. A new activity subclass
      3. Declaring activities in the manifest
      4. Adding a cheat button to MainActivity
    2. Starting an Activity
      1. Communicating with intents
        1. Explicit and implicit intents
    3. Passing Data Between Activities
      1. Using intent extras
      2. Getting a result back from a child activity
        1. Setting a result
        2. Sending back an intent
        3. Handling a result
    4. How Android Sees Your Activities
    5. For the More Curious: startActivityForResult
    6. For the More Curious: The Back Button and the Activity Lifecycle
    7. Challenge: Closing Loopholes for Cheaters
    8. Challenge: Tracking Cheat Status by Question
  14. 8. Android SDK Versions and Compatibility
    1. Android SDK Versions
      1. A sane minimum
      2. Minimum SDK version
      3. Target SDK version
      4. Compile SDK version
    2. Compatibility and Android Programming
      1. Jetpack libraries
      2. Safely adding code from later APIs
    3. Using the Android Developer Documentation
    4. Challenge: Reporting the Device’s Android Version
    5. Challenge: Limited Cheats
  15. 9. Fragments
    1. The Need for UI Flexibility
    2. Introducing Fragments
    3. Starting CriminalIntent
      1. Creating a new project
    4. Creating a Data Class
    5. Creating a Fragment
      1. Defining CrimeDetailFragment’s layout
      2. Creating the CrimeDetailFragment class
        1. Different types of fragments
        2. Implementing fragment lifecycle functions
        3. Wiring up views in a fragment
    6. Hosting a Fragment
      1. Defining a FragmentContainerView
      2. The FragmentManager
      3. The fragment lifecycle
      4. Fragments and memory management
    7. Challenge: Testing with FragmentScenario
  16. 10. Displaying Lists with RecyclerView
    1. Adding a New Fragment and ViewModel
      1. ViewModel lifecycle with fragments
    2. Adding a RecyclerView
    3. Implementing a LayoutManager
    4. Creating an Item View Layout
    5. Implementing a ViewHolder
    6. Implementing an Adapter to Populate the RecyclerView
      1. Setting the RecyclerView’s adapter
    7. Recycling Views
    8. Cleaning Up Binding List Items
    9. Responding to Presses
    10. Lists and Grids: Past, Present, and Future
    11. For the More Curious: A Smarter Adapter with ListAdapter
    12. Challenge: RecyclerView View Types
  17. 11. Creating User Interfaces with Layouts and Views
    1. Introducing ConstraintLayout
    2. Introducing the Layout Editor
    3. Using ConstraintLayout
      1. Making room
      2. Adding views
      3. ConstraintLayout’s inner workings
      4. Editing properties
      5. Making list items dynamic
    4. Styles, Themes, and Theme Attributes
    5. For the More Curious: Margins vs Padding
    6. For the More Curious: Advanced Features in ConstraintLayout
    7. Challenge: Formatting the Date
  18. 12. Coroutines and Databases
    1. An Introduction to Asynchronous Code on Android
      1. Using coroutines
      2. Consuming data from coroutines
    2. Creating a Database
      1. Room architecture component library
      2. Defining entities
      3. Creating a database class
      4. Creating a type converter
      5. Defining a Data Access Object
    3. Accessing the Database Using the Repository Pattern
    4. Importing Prepopulated Data
    5. Querying the Database
    6. Keeping the Changes Flowing
    7. Challenge: Addressing the Schema Warning
    8. For the More Curious: Singletons
  19. 13. Fragment Navigation
    1. Performing Navigation
      1. Implementing the Navigation component library
      2. Navigating to the detail screen
      3. Passing data to a fragment
    2. Unidirectional Data Flow
    3. Updating the Database
    4. For the More Curious: A Better List Preview
    5. Challenge: No Untitled Crimes
  20. 14. Dialogs and DialogFragment
    1. Creating a DialogFragment
      1. Showing a DialogFragment
    2. Passing Data Between Two Fragments
      1. Passing data to DatePickerFragment
      2. Returning data to CrimeDetailFragment
        1. Setting a fragment result
    3. Challenge: More Dialogs
  21. 15. The App Bar
    1. The Default App Bar
    2. Menus
      1. Defining a menu in XML
        1. The app namespace
      2. Creating the menu
      3. Responding to menu selections
    3. For the More Curious: App Bar vs Action Bar vs Toolbar
    4. For the More Curious: Accessing the AppCompat App Bar
    5. Challenge: An Empty View for the RecyclerView
    6. Challenge: Deleting Crimes
  22. 16. Implicit Intents
    1. Adding Buttons
    2. Adding a Suspect Property
    3. Using a Format String
    4. Using Implicit Intents
      1. Parts of an implicit intent
      2. Sending a crime report
      3. Asking Android for a contact
        1. Getting data from the contacts list
        2. Contacts permissions
      4. Checking for responding activities
        1. Disclosing queries
        2. Querying the PackageManager
    5. Challenge: Another Implicit Intent
  23. 17. Taking Pictures with Intents
    1. A Place for Your Photo
    2. File Storage
      1. Using FileProvider
      2. Designating a picture location
    3. Using a Camera Intent
    4. Scaling and Displaying Bitmaps
    5. Declaring Features
    6. Challenge: Detail Display
  24. 18. Localization
    1. Localizing Resources
      1. Default resources
      2. Checking string coverage using the Translations Editor
      3. Targeting a region
    2. Configuration Qualifiers
      1. Prioritizing alternative resources
      2. Multiple qualifiers
      3. Finding the best-matching resources
    3. Testing Alternative Resources
    4. For the More Curious: More on Determining Device Size
    5. Challenge: Localizing Dates
  25. 19. Accessibility
    1. TalkBack
      1. Explore by Touch
      2. Linear navigation by swiping
    2. Making Non-Text Elements Readable by TalkBack
      1. Adding content descriptions
      2. Making a view focusable
    3. Creating a Comparable Experience
    4. For the More Curious: Using TalkBack with an Emulator
    5. For the More Curious: Using Accessibility Scanner
    6. Challenge: Improving the List
    7. Challenge: Providing Enough Context for Data Entry
    8. Challenge: Announcing Events
  26. 20. Making Network Requests and Displaying Images
    1. Creating PhotoGallery
    2. Networking Basics with Retrofit
      1. Defining an API interface
      2. Building the Retrofit object and creating an API instance
        1. Adding a String converter
      3. Executing a web request
      4. Asking permission to network
      5. Moving toward the repository pattern
    3. Fetching JSON from Flickr
      1. Deserializing JSON text into model objects
      2. Handling errors
    4. Networking Across Configuration Changes
    5. Displaying Results in RecyclerView
      1. Displaying images
    6. For the More Curious: Managing Dependencies
    7. Challenge: Paging
  27. 21. SearchView and DataStore
    1. Searching Flickr
    2. Using SearchView
      1. Responding to SearchView user interactions
    3. Simple Persistence with DataStore
    4. Defining UI State
    5. Challenge: Polishing Your App Some More
  28. 22. WorkManager
    1. Creating a Worker
    2. Scheduling Work
    3. Checking for New Photos
    4. Notifying the User
    5. Providing User Control over Polling
  29. 23. Browsing the Web and WebView
    1. One Last Bit of Flickr Data
    2. The Easy Way: Implicit Intents
    3. The Harder Way: WebView
      1. WebChromeClient
    4. WebView vs a Custom UI
    5. For the More Curious: WebView Updates
    6. For the More Curious: Chrome Custom Tabs (Another Easy Way)
    7. Challenge: Using the Back Button for Browser History
  30. 24. Custom Views and Touch Events
    1. Setting Up the DragAndDraw Project
    2. Creating a Custom View
      1. Creating BoxDrawingView
    3. Handling Touch Events
      1. Tracking across motion events
    4. Rendering Inside onDraw(Canvas)
    5. For the More Curious: Detecting Gestures
    6. Challenge: Saving State
    7. Challenge: Rotating Boxes
    8. Challenge: Accessibility Support
  31. 25. Property Animation
    1. Building the Scene
    2. Simple Property Animation
      1. View transformation properties
      2. Using different interpolators
      3. Color evaluation
    3. Playing Animators Together
    4. For the More Curious: Other Animation APIs
      1. Legacy animation tools
      2. Transitions
    5. Challenges
  32. 26. Introduction to Jetpack Compose
    1. Creating a Compose Project
    2. Composing Your First UI
    3. Layouts in Compose
    4. Composable Functions
    5. Previewing Composables
    6. Customizing Composables
      1. Declaring inputs on a composable function
        1. Resources in Compose
        2. Control flow in a composable
      2. Aligning elements in a row
      3. Specifying text styles
    7. The Compose Modifier
      1. The padding modifier
      2. Chaining modifiers and modifier ordering
      3. The clickable modifier
      4. Sizing composables
      5. Specifying a modifier parameter
    8. Building Screens with Composables
    9. Scrollable Lists with LazyColumn
    10. For the More Curious: Live Literals
  33. 27. UI State in Jetpack Compose
    1. Philosophies of State
    2. Defining Your UI State
    3. Updating UIs with MutableState
    4. Recomposition
    5. remember
    6. State Hoisting
    7. State and Configuration Changes
      1. Parcelable and Parcelize
    8. For the More Curious: Coroutines, Flow, and Compose
    9. For the More Curious: Scrolling State
    10. For the More Curious: Inspecting Compose Layouts
  34. 28. Showing Dialogs with Jetpack Compose
    1. Your First Dialog in Compose
    2. Dismissing the Dialog
    3. Setting the Dialog’s Content
    4. Sending Results from a Dialog
    5. Challenge: Pizza Sizes and Drop-Down Menus
  35. 29. Theming Compose UIs
    1. Images
      1. Image’s contentDescription
      2. Adding more images
      3. Customizing the Image composable
        1. aspectRatio
        2. contentScale
        3. Image alignment
        4. The align modifier
      4. Adding a header to LazyColumn
    2. MaterialTheme
    3. Scaffold and TopAppBar
    4. CompositionLocal
    5. Removing AppCompat
    6. For the More Curious: Accompanist
    7. For the More Curious: Creating Your Own CompositionLocals
    8. Challenge: Animations
  36. 30. Afterword
    1. The Final Challenge
    2. Shameless Plugs
    3. Thank You
  37. Index

Product information

  • Title: Android Programming: The Big Nerd Ranch Guide, 5th Edition
  • Author(s): Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
  • Release date: May 2022
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 9780137645794