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 10. A Framework for a Well-Behaved Application

In this chapter and the next, we introduce framework, or skeleton, applications that exemplify many of the design and implementation approaches presented in this book, especially in Chapter 3 where we introduced the components of an application.

The framework application in this chapter can be used as a starting point for your own applications. We recommend this approach to creating applications over starting from scratch, or from smaller examples that do not implement all the aspects of the Activity object and activity life cycle.

The approach we take in this chapter enables you to visualize and understand the component life cycle before you know you need it. Retrofitting life cycle handling to an application that was written without understanding life cycles, or with the expectation that life cycle handling won’t be needed, is one of the easiest ways to create an Android application that fails unexpectedly, in ways that are hard to reproduce consistently, and that has persistent bugs that can remain undiscovered across multiple attempts to eradicate them. In other words, it’s best to learn this before it bites you in the ass.

This chapter isn’t about user interfaces, but you should keep in mind that the Android user interface classes were designed with both the constraints of the Android architecture and the capabilities of the Android system in mind. Implementations of user interface and life cycle handling go hand in hand. ...

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