You are previewing Programming Android, 2nd Edition.

Programming Android, 2nd Edition

Cover of Programming Android, 2nd Edition by G. Blake Meike... Published by O'Reilly Media, Inc.
  1. Programming Android
  2. Preface
    1. How This Book Is Organized
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari® Books Online
    5. How to Contact Us
    6. Acknowledgments
  3. I. Tools and Basics
    1. 1. Installing the Android SDK and Prerequisites
      1. Installing the Android SDK and Prerequisites
      2. Test Drive: Confirm That Your Installation Works
      3. Components of the SDK
      4. Keeping Up-to-Date
      5. Example Code
      6. On Reading Code
    2. 2. Java for Android
      1. Android Is Reshaping Client-Side Java
      2. The Java Type System
      3. Scope
      4. Idioms of Java Programming
    3. 3. The Ingredients of an Android Application
      1. Traditional Programming Models Compared to Android
      2. Activities, Intents, and Tasks
      3. Other Android Components
      4. Component Life Cycles
      5. Static Application Resources and Context
      6. The Android Application Runtime Environment
      7. Extending Android
      8. Concurrency in Android
      9. Serialization
    4. 4. Getting Your Application into Users’ Hands
      1. Application Signing
      2. Placing an Application for Distribution in the Android Market
      3. Alternative Distribution
      4. Google Maps API Keys
      5. Specifying API-Level Compatibility
      6. Compatibility with Many Kinds of Screens
    5. 5. Eclipse for Android Software Development
      1. Eclipse Concepts and Terminology
      2. Eclipse Views and Perspectives
      3. Java Coding in Eclipse
      4. Eclipse and Android
      5. Preventing Bugs and Keeping Your Code Clean
      6. Eclipse Idiosyncrasies and Alternatives
  4. II. About the Android Framework
    1. 6. Building a View
      1. Android GUI Architecture
      2. Assembling a Graphical Interface
      3. Wiring Up the Controller
      4. The Menu and the Action Bar
      5. View Debugging and Optimization
    2. 7. Fragments and Multiplatform Support
      1. Creating a Fragment
      2. Fragment Life Cycle
      3. The Fragment Manager
      4. Fragment Transactions
      5. The Support Package
      6. Fragments and Layout
    3. 8. Drawing 2D and 3D Graphics
      1. Rolling Your Own Widgets
      2. Bling
    4. 9. Handling and Persisting Data
      1. Relational Database Overview
      2. SQLite
      3. The SQL Language
      4. SQL and the Database-Centric Data Model for Android Applications
      5. The Android Database Classes
      6. Database Design for Android Applications
      7. Using the Database API: MJAndroid
  5. III. A Skeleton Application for Android
    1. 10. A Framework for a Well-Behaved Application
      1. Visualizing Life Cycles
      2. Visualizing the Fragment Life Cycle
      3. The Activity Class and Well-Behaved Applications
      4. Life Cycle Methods of the Application Class
    2. 11. Building a User Interface
      1. Top-Level Design
      2. Visual Editing of User Interfaces
      3. Starting with a Blank Slate
      4. Laying Out the Fragments
      5. Folding and Unfolding a Scalable UI
      6. Making Activity, Fragment, Action Bar, and Multiple Layouts Work Together
      7. The Other Activity
    3. 12. Using Content Providers
      1. Understanding Content Providers
      2. Defining a Provider Public API
      3. Writing and Integrating a Content Provider
      4. File Management and Binary Data
      5. Android MVC and Content Observation
      6. A Complete Content Provider: The SimpleFinchVideoContentProvider Code
      7. Declaring Your Content Provider
    4. 13. A Content Provider as a Facade for a RESTful Web Service
      1. Developing RESTful Android Applications
      2. A “Network MVC”
      3. Summary of Benefits
      4. Code Example: Dynamically Listing and Caching YouTube Video Content
      5. Structure of the Source Code for the Finch YouTube Video Example
      6. Stepping Through the Search Application
      7. Step 1: Our UI Collects User Input
      8. Step 2: Our Controller Listens for Events
      9. Step 3: The Controller Queries the Content Provider with a managedQuery on the Content Provider/Model
      10. Step 4: Implementing the RESTful Request
  6. IV. Advanced Topics
    1. 14. Search
      1. Search Interface
      2. Query Suggestions
    2. 15. Location and Mapping
      1. Location-Based Services
      2. Mapping
      3. The Google Maps Activity
      4. The MapView and MapActivity
      5. Working with MapViews
      6. MapView and MyLocationOverlay Initialization
      7. Pausing and Resuming a MapActivity
      8. Controlling the Map with Menu Buttons
      9. Controlling the Map with the Keypad
      10. Location Without Maps
      11. StreetView
    3. 16. Multimedia
      1. Audio and Video
      2. Playing Audio and Video
      3. Recording Audio and Video
      4. Stored Media Content
    4. 17. Sensors, NFC, Speech, Gestures, and Accessibility
      1. Sensors
      2. Near Field Communication (NFC)
      3. Gesture Input
      4. Accessibility
    5. 18. Communication, Identity, Sync, and Social Media
      1. Account Contacts
      2. Authentication and Synchronization
      3. Bluetooth
    6. 19. The Android Native Development Kit (NDK)
      1. Native Methods and JNI Calls
      2. The Android NDK
      3. Native Libraries and Headers Provided by the NDK
      4. Building Your Own Custom Library Modules
      5. Native Activities
  7. Index
  8. About the Authors
  9. Colophon
  10. Copyright
O'Reilly logo

Chapter 13. A Content Provider as a Facade for a RESTful Web Service

In Chapter 6, we saw that user interfaces that need to interact with remote services face interesting challenges, such as not tying up the UI thread with long-running tasks. We also noted in Chapter 3 that the Android content provider API shares symmetry with REST-style web services. Content provider data operations map straight onto REST data operations, and now we’ll show you how to translate content provider URIs to request network data. We suggest taking advantage of this symmetry by writing content providers to operate as an asynchronous buffer between the domain or unique aspects of your application, and the network requests that acquire the data on which your application operates. Writing your application in this way will simplify your application, and will solve common UI and network programming errors encountered in Android and other types of Java programming.

Historically, Java UI programmers, both enterprise and mobile, have written mobile and desktop-based applications in a rather brittle way, and sometimes did run network requests directly on the UI thread, often without caching data obtained from those requests. In most applications, showing anything in a UI would require accessing the network every time a user requested the display of data. Believe it or not, Unix workstations from the 1980s and 1990s would frequently lock up when access to remotely mounted filesystems became unavailable. If applications ...

The best content for your career. Discover unlimited learning on demand for around $1/day.