Advanced Android™ Application Development, Fourth Edition

Advanced Android™ Application Development, Fourth Edition

Read it now on the O’Reilly learning platform with a 10-day free trial.

O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.

Book description

Advanced Android™ Application Development, Fourth Edition, is the definitive guide to building robust, commercial-grade Android apps. Systematically revised and updated, this guide brings together powerful, advanced techniques for the entire app development cycle, including design, coding, testing, debugging, and distribution. With the addition of quizzes and exercises in every chapter, it is ideal for both professional and classroom use.

An outstanding practical reference for the newest Android APIs, this guide provides in-depth explanations of code utilizing key API features and includes downloadable sample apps for nearly every chapter. Together, they provide a solid foundation for any modern app project.

Throughout, the authors draw on decades of in-the-trenches experience as professional mobile developers to provide tips and best practices for highly efficient development. They show you how to break through traditional app boundaries with optional features, including the Android NDK, Google Analytics and Android Wear APIs, and Google Play Game Services.

New coverage in this edition includes

Annuzzi has released new source code samples for use with Android Studio. The code updates are posted to the associated blog site: http://advancedandroidbook.blogspot.com/

This title is an indispensable resource for intermediate- to advanced-level Java programmers who are now developing for Android, and for seasoned mobile developers who want to make the most of the new Android platform and hardware.

This revamped, newly titled edition is a complete update of Android™ Wireless Application Development, Volume II: Advanced Topics, Third Edition.

Show and hide more Table of contents Product information

Table of contents

  1. About This eBook
  2. Title Page
  3. Copyright Page
  4. Praise for Advanced Android™ Application Development, Fourth Edition
  5. Dedication Page
  6. Contents at a Glance
  7. Contents
  8. Acknowledgments
  9. About the Authors
  10. Introduction
    1. Who Should Read This Book?
    2. How This Book Is Structured
    3. Key Questions Answered in This Book
    4. An Overview of Changes in This Edition
    5. The Development Environment Used in This Book
    6. Supplementary Materials Available
    7. Where to Find More Information
    8. Conventions Used in This Book
    9. Contacting the Authors
    1. 1. Threading and Asynchronous Processing
      1. The Importance of Processing Asynchronously
      2. Working with the AsyncTask Class
      3. Working with the Thread Class
      4. Working with Loaders
      5. Understanding StrictMode
      6. Summary
      7. Quiz Questions
      8. Exercises
      9. References and More Information
      1. Determining When to Use Services
      2. Understanding the Service Lifecycle
      3. Creating a Service
      4. Controlling a Service
      5. Implementing a Remote Interface
      6. Implementing a Parcelable Class
      7. Using the IntentService Class
      8. Summary
      9. Quiz Questions
      10. Exercises
      11. References and More Information
      1. Storing Structured Data Using SQLite Databases
        1. Creating a SQLite Database
        2. Creating, Updating, and Deleting Database Records
        3. Working with Transactions
        1. Working with Cursors
        2. Executing Simple Queries
        3. Executing More Complex Queries Using SQLiteQueryBuilder
        4. Executing Raw Queries without Builders and Column Mapping
        1. Deleting Tables and Other SQLite Objects
        2. Closing a SQLite Database
        3. Deleting a SQLite Database Instance Using the Application Context
        1. Keeping Track of Database Field Names
        2. Extending the SQLiteOpenHelper Class
        1. Working with Database Data Like Any Other Data
        2. Binding Data to Controls Using Data Adapters
        1. Acting as a Content Provider
          1. Implementing a Content Provider Interface
          2. Defining the Data URI
          3. Defining Data Columns
          4. Implementing Important Content Provider Methods
          5. Updating the Manifest File
          1. Sending Broadcasts
            1. Sending Basic Broadcasts
            2. Sending Ordered Broadcasts
            1. Registering to Receive Broadcasts
            2. Handling Incoming Broadcasts from the System
            1. Notifying the User
            2. A Word on Compatibility
            3. Notifying with the Status Bar
              1. Using the NotificationManager Service
              2. Creating a Simple Text Notification with an Icon
              3. Working with the Notification Queue
              4. Updating Notifications
              5. Clearing Notifications
              1. 7. Designing Powerful User Interfaces
                1. Following Android User Interface Guidelines
                2. Enabling Action Bars
                  1. Building Basic Action Bars
                  2. Customizing Your Action Bar
                  3. Handling Application Icon Clicks on the Action Bar
                  4. Working with Screens That Do Not Require Action Bars
                  5. Contextual Action Mode
                  1. Building Simple Styles
                  2. Leveraging Style Inheritance
                  1. Working with Textual Input Methods
                    1. Working with Software Keyboards
                    2. Working with Text Prediction and User Dictionaries
                    3. Using the Clipboard Framework
                    1. Listening for Touch Mode Changes
                    2. Listening for Events on the Entire Screen
                    3. Listening for Long Clicks
                    4. Listening for Focus Changes
                    1. Detecting User Motions within a View
                    2. Handling Common Single-Touch Gestures
                    3. Handling Common Multitouch Gestures
                    4. Making Gestures Look Natural
                    5. Using the Drag-and-Drop Framework
                    1. Exploring the Accessibility Framework
                    2. Leveraging Speech Recognition Services
                    3. Leveraging Text-to-Speech Services
                    4. Testing Application Accessibility
                    5. Summary
                    6. Quiz Questions
                    7. Exercises
                    8. References and More Information
                    1. Understanding Device Diversity
                      1. Don’t Make Assumptions about Device Characteristics
                      2. Designing Flexible User Interfaces
                      3. Attracting New Types of Users
                      4. Leveraging Alternative Resources
                      5. Using Screen Space Effectively on Big Landscape Screens
                      1. Working with Google TV
                      2. Google TV Variations
                      1. 11. Using Android Networking APIs
                        1. Understanding Mobile Networking Fundamentals
                        2. Understanding StrictMode with Networking
                        3. Accessing the Internet (HTTP)
                          1. Reading Data from the Web
                          2. Using HttpURLConnection
                          3. Parsing XML from the Network
                          4. Handling Network Operations Asynchronously
                          5. Retrieving Android Network Status
                          1. Browsing the Web with WebView
                            1. Designing a Layout with a WebView Control
                            2. Loading Content into a WebView Control
                            3. Adding Features to the WebView Control
                            4. Managing WebView State
                            1. Browsing the WebKit APIs
                            2. Extending Web Application Functionality to Android
                            1. Working with Multimedia
                            2. Working with the Camera
                              1. Capturing Still Images Using the Camera
                              2. Configuring Camera Mode Settings
                              3. Working with Common Camera Parameters
                              4. Zooming the Camera
                              5. Sharing Images
                              6. Assigning Images as Wallpapers
                              7. Choosing among Various Device Cameras
                              1. Recording Video
                              2. Playing Video
                              1. Recording Audio
                              2. Playing Audio
                              3. Sharing Audio
                              1. Working with Telephony Utilities
                                1. Gaining Permission to Access Phone State Information
                                2. Requesting Call State
                                3. Requesting Service Information
                                4. Monitoring Signal Strength and Data Connection Speed
                                5. Working with Phone Numbers
                                1. Default Messaging Application
                                2. SMS Provider
                                3. SMS Applications Other than the Default
                                1. Making Phone Calls
                                2. Receiving Phone Calls
                                1. Interacting with Device Hardware
                                2. Using the Device Sensors
                                  1. Working with Different Sensors
                                  2. Configuring the Android Manifest File for Sensors
                                  3. Acquiring a Reference to a Sensor
                                  4. Reading Sensor Data
                                  5. Calibrating Sensors
                                  6. Determining Device Orientation
                                  7. Finding True North
                                  1. Working with Bluetooth
                                    1. Checking for the Existence of Bluetooth Hardware
                                    2. Enabling Bluetooth
                                    3. Querying for Paired Devices
                                    4. Discovering Devices
                                    5. Establishing Connections between Devices
                                    1. Working with USB Accessories
                                    2. Working as a USB Host
                                    1. Enabling Android Beam Sending
                                    2. Receiving Android Beam Messages
                                    3. Configuring the Manifest File for Android Beam
                                    4. Android Beam over Bluetooth
                                    5. Introducing Host Card Emulation
                                    1. Introducing Wi-Fi Direct
                                    2. Monitoring Wi-Fi State
                                    1. 17. Using Location and Map APIs
                                      1. Incorporating Android Location APIs
                                        1. Using the Global Positioning System (GPS)
                                        2. Geocoding Locations
                                        3. Doing More with Android Location-Based Services
                                        1. Locating with the Fused Location Provider
                                        2. Doing More with Google Location Services
                                        1. Mapping Locations
                                        1. An Overview of GCM
                                          1. Understanding GCM Message Flow
                                          2. Understanding the Limitations of the GCM Service
                                          3. Signing Up for GCM
                                          4. Incorporating GCM into Your Applications
                                          5. Exploring the GCM Sample Applications
                                          1. What Is In-App Billing?
                                          2. Using In-App Billing
                                          3. Leveraging Google Play In-App Billing APIs
                                          4. Leveraging Amazon Appstore for Android In-App Purchasing APIs
                                          5. Leveraging PayPal Billing APIs
                                          6. Leveraging Other Billing APIs
                                          7. Summary
                                          8. Quiz Questions
                                          9. Exercises
                                          10. References and More Information
                                          1. Creating a Google Account for Analytics
                                          2. Adding the Library to Your Android IDE Project
                                          3. Collecting Data from Your Applications
                                          4. Logging Different Events
                                          5. Using the Google Analytics Dashboard
                                          6. Gathering E-commerce Information
                                            1. Logging E-commerce Events in Your Applications
                                            2. Reviewing E-commerce Reports
                                            1. Getting Up and Running with Google Play Game Services
                                            2. Incorporating Google Play Game Services into Your Applications
                                            3. Understanding Achievements
                                            4. Understanding Leaderboards
                                            5. Saving Game Data with Cloud Save
                                            6. Introducing Multiplayer Gaming
                                            7. Understanding Antipiracy
                                            8. Summary
                                            9. Quiz Questions
                                            10. Exercises
                                            11. References and More Information
                                            1. 22. Developing Android 2D Graphics Applications
                                              1. Drawing on the Screen
                                                1. Working with Canvases and Paints
                                                2. Understanding the Canvas Object
                                                3. Understanding the Paint Object
                                                1. Using Default Fonts and Typefaces
                                                2. Using Custom Typefaces
                                                3. Measuring Text Screen Requirements
                                                1. Drawing Bitmap Graphics on a Canvas
                                                2. Scaling Bitmap Graphics
                                                3. Transforming Bitmaps Using Matrixes
                                                4. Bitmap Performance Optimizations
                                                1. Defining Shape Drawables as XML Resources
                                                2. Defining Shape Drawables Programmatically
                                                3. Drawing Different Shapes
                                                1. Controlling Hardware Acceleration
                                                2. Fine-Tuning Hardware Acceleration
                                                1. Animating Your Applications
                                                  1. Working with Drawable Animation
                                                  2. Working with View Animations
                                                  3. Working with Property Animation
                                                  1. Working with OpenGL ES
                                                    1. Leveraging OpenGL ES in Android
                                                    2. Ensuring Device Compatibility
                                                    1. Creating a SurfaceView
                                                    2. Starting Your OpenGL ES Thread
                                                    3. Initializing EGL
                                                    4. Initializing GL
                                                    5. Drawing on the Screen
                                                    1. Drawing Your Vertices
                                                    2. Coloring Your Vertices
                                                    3. Drawing More Complex Objects
                                                    4. Lighting Your Scene
                                                    5. Texturing Your Objects
                                                    1. Enabling the OpenGL Thread to Talk to the Application Thread
                                                    2. Enabling the Application Thread to Talk to the OpenGL Thread
                                                    1. Configuring Your Application for OpenGL ES 2.0
                                                    2. Requesting an OpenGL ES 2.0 Surface
                                                    1. Determining When to Use the Android NDK
                                                    2. Installing the Android NDK
                                                    3. Exploring the Android NDK Sample Application
                                                    4. Creating Your Own NDK Project
                                                      1. Calling Native Code from Java
                                                      2. Handling Parameters and Return Values
                                                      3. Using Exceptions with Native Code
                                                      4. Using Native Activities
                                                      1. Computing with RenderScript
                                                      2. Native RenderScript
                                                      1. 26. Extending Android Application Reach
                                                        1. Enhancing Your Applications
                                                        2. Working with App Widgets
                                                          1. Creating an App Widget
                                                          2. Installing an App Widget to the Home Screen
                                                          3. Becoming an App Widget Host
                                                          4. Introducing Lock Screen App Widgets
                                                          5. Installing an App Widget to the Lock Screen
                                                          1. Creating a Live Wallpaper Service
                                                          2. Creating a Live Wallpaper Configuration
                                                          3. Configuring the Android Manifest File for Live Wallpapers
                                                          4. Installing a Live Wallpaper
                                                          1. Implementing the Activity to Process the Intents
                                                          2. Registering the Intent Filter
                                                          1. Making Application Content Searchable
                                                          2. Enabling Searches in Your Application
                                                            1. Creating a Search Configuration
                                                            2. Creating a Search Activity
                                                            3. Configuring the Android Manifest File for Search
                                                            1. Updating a Search Configuration for Global Searches
                                                            2. Updating Search Settings for Global Searches
                                                            1. Managing Accounts with the Account Manager
                                                              1. Multiple Users, Restricted Profiles, and Accounts
                                                              1. Choosing a Remote Backup Service
                                                              2. Implementing a Backup Agent
                                                              3. Backing Up and Restoring Application Data
                                                              1. 29. Internationalizing Your Applications
                                                                1. Localizing Your Application’s Language
                                                                  1. Internationalization Using Alternative Resources
                                                                  2. Changing the Language Settings
                                                                  3. Implementing Locale Support Programmatically
                                                                  1. Using the Developer Console
                                                                  1. All Applications Are Vulnerable
                                                                  2. Using Secure Coding Practices
                                                                  3. Obfuscating with ProGuard
                                                                    1. Configuring ProGuard for Your Android Applications
                                                                    2. Dealing with Error Reports after Obfuscation
                                                                    1. 31. Introducing the L Developer Preview
                                                                      1. Exploring the L Developer Preview
                                                                        1. Improving Performance
                                                                        2. Improving the User Experience
                                                                        1. Understanding Android TV Development Requirements
                                                                        2. Understanding TV Application Hardware Limitations
                                                                        1. A. Quick-Start Guide: Android Debug Bridge
                                                                          1. Listing Connected Devices and Emulators
                                                                          2. Directing ADB Commands to Specific Devices
                                                                          3. Starting and Stopping the ADB Server
                                                                            1. Stopping the ADB Server Process
                                                                            2. Starting and Checking the ADB Server Process
                                                                            1. Issuing a Single Shell Command
                                                                            2. Using a Shell Session
                                                                            3. Using the Shell to Start and Stop the Emulator
                                                                            1. Sending Files to a Device or Emulator
                                                                            2. Retrieving Files from a Device or Emulator
                                                                            1. Installing Applications
                                                                            2. Reinstalling Applications
                                                                            3. Uninstalling Applications
                                                                            1. Displaying All Log Information
                                                                            2. Including Date and Time with Log Data
                                                                            3. Filtering Log Information
                                                                            4. Clearing the Log
                                                                            5. Redirecting Log Output to a File
                                                                            6. Accessing the Secondary Logs
                                                                            1. Forcing Backup Operations
                                                                            2. Forcing Restore Operations
                                                                            3. Wiping Archived Data
                                                                            1. Letting the Monkey Loose on Your Application
                                                                            2. Listening to Your Monkey
                                                                            3. Directing Your Monkey’s Actions
                                                                            4. Training Your Monkey to Repeat His Tricks
                                                                            5. Keeping the Monkey on a Leash
                                                                            6. Learning More about Your Monkey
                                                                            1. Exploring Common Tasks with SQLite
                                                                            2. Using the sqlite3 Command-Line Interface
                                                                              1. Launching the ADB Shell
                                                                              2. Connecting to a SQLite Database
                                                                              3. Exploring Your Database
                                                                              4. Importing and Exporting the Database and Its Data
                                                                              5. Executing SQL Commands on the Command Line
                                                                              6. Using Other sqlite3 Commands
                                                                              7. Understanding SQLite Limitations
                                                                              1. Designing the Student Grade Database Schema
                                                                              2. Creating Simple Tables with AUTOINCREMENT
                                                                              3. Inserting Data into Tables
                                                                              4. Querying Tables for Results with SELECT
                                                                              5. Using Foreign Keys and Composite Primary Keys
                                                                              6. Altering and Updating Data in Tables
                                                                              7. Querying Multiple Tables Using JOIN
                                                                              8. Using Calculated Columns
                                                                              9. Using Subqueries for Calculated Columns
                                                                              10. Deleting Tables
                                                                              1. Learning the Java Programming Language
                                                                              2. Learning the Java Development Tools
                                                                              3. Familiarizing Yourself with Java Documentation
                                                                              4. Understanding Java Shorthand
                                                                                1. Chaining Methods and Unnecessary Temp Variables
                                                                                2. Looping Infinitely
                                                                                3. Working with Unary and Ternary Operators
                                                                                4. Working with Inner Classes
                                                                                1. Getting Up and Running with Android Studio
                                                                                  1. Launching Android Studio for the First Time
                                                                                  2. Configuring Android Studio
                                                                                  3. Creating an Android Studio Project
                                                                                  1. Working in Design View
                                                                                  2. Working in Text View
                                                                                  3. Using the Preview Controls
                                                                                  1. Setting Breakpoints
                                                                                  2. Stepping through Code
                                                                                  1. Chapter 1
                                                                                  2. Chapter 2
                                                                                  3. Chapter 3
                                                                                  4. Chapter 4
                                                                                  5. Chapter 5
                                                                                  6. Chapter 6
                                                                                  7. Chapter 7
                                                                                  8. Chapter 8
                                                                                  9. Chapter 9
                                                                                  10. Chapter 10
                                                                                  11. Chapter 11
                                                                                  12. Chapter 12
                                                                                  13. Chapter 13
                                                                                  14. Chapter 14
                                                                                  15. Chapter 15
                                                                                  16. Chapter 16
                                                                                  17. Chapter 17
                                                                                  18. Chapter 18
                                                                                  19. Chapter 19
                                                                                  20. Chapter 20
                                                                                  21. Chapter 21
                                                                                  22. Chapter 22
                                                                                  23. Chapter 23
                                                                                  24. Chapter 24
                                                                                  25. Chapter 25
                                                                                  26. Chapter 26
                                                                                  27. Chapter 27
                                                                                  28. Chapter 28
                                                                                  29. Chapter 29
                                                                                  30. Chapter 30
                                                                                  31. Chapter 31
                                                                                  32. Appendix A
                                                                                  33. Appendix B
                                                                                  34. Appendix C
                                                                                  35. Appendix D
                                                                                  Show and hide more

                                                                                  Product information

                                                                                  • Title: Advanced Android™ Application Development, Fourth Edition
                                                                                  • Author(s): Joseph Annuzzi Jr., Lauren Darcey, Shane Conder
                                                                                  • Release date: November 2014
                                                                                  • Publisher(s): Addison-Wesley Professional
                                                                                  • ISBN: 9780133892420