Preface
Part I. Tools and Basics
1. Your Toolkit
Installing the Android SDK and Prerequisites
The Java Development Kit (JDK)
The Eclipse Integrated Development Environment (IDE)
The Android SDK
Adding Build Targets to the SDK
The Android Development Toolkit (ADT) Plug-in for Eclipse
Test Drive: Confirm That Your Installation Works
Making an Android Project
Making an Android Virtual Device (AVD)
Running a Program on an AVD
Running a Program on an Android Device
Troubleshooting SDK Problems: No Build Targets
Components of the SDK
The Android Debug Bridge (adb)
The Dalvik Debug Monitor Server (DDMS)
Components of the ADT Eclipse Plug-in
Android Virtual Devices
Other SDK Tools
Keeping Up-to-Date
Keeping the Android SDK Up-to-Date
Keeping Eclipse and the ADT Plug-in Up-to-Date
Keeping the JDK Up-to-Date
Example Code
SDK Example Code
Example Code from This Book
On Reading Code
2. Java for Android
Android Is Reshaping Client-Side Java
The Java Type System
Primitive Types
Objects and Classes
Object Creation
The Object Class and Its Methods
Objects, Inheritance, and Polymorphism
Final and Static Declarations
Abstract Classes
Interfaces
Exceptions
The Java Collections Framework
Garbage Collection
Scope
Java Packages
Access Modifiers and Encapsulation
Idioms of Java Programming
Type Safety in Java
Using Anonymous Classes
Modular Programming in Java
Basic Multithreaded Concurrent Programming in Java
Synchronization and Thread Safety
Thread Control with wait() and notify() Methods
Synchronization and Data Structures
3. The Ingredients of an Android Application
Traditional Programming Models Compared to Android
Activities, Intents, and Tasks
Other Android Components
Service
Content Providers
BroadcastReceiver
Static Application Resources and Context
Application Manifests
A Typical Source Tree
Initialization Parameters in AndroidManifest.xml
Resources
The Android Application Runtime Environment
The Dalvik VM
Zygote: Forking a New Process
Sandboxing: Processes and Users
Component Life Cycles
The Activity Life Cycle
Packaging an Android Application: The .apk File
On Porting Software to Android
4. Getting Your Application into Users’ Hands
Application Signing
Public Key Encryption and Cryptographic Signing
How Signatures Protect Software Users, Publishers, and
Secure Communications
Signing an Application
Placing an Application for Distribution in the Android Market
Becoming an Official Android Developer
Uploading Applications in the Market
Getting Paid
Google Maps API Keys
Specifying API-Level Compatibility
Compatibility with Many Kinds of Screens
Testing for Screen Size Compatibility
Resource Qualifiers and Screen Sizes
5. Eclipse for Android Software Development
Eclipse Concepts and Terminology
Plug-ins
Workspaces
Java Environments
Projects
Builders and Artifacts
Extensions
Associations
Eclipse Views and Perspectives
The Package Explorer View
The Task List View
The Outline View
The Problems View
Java Coding in Eclipse
Editing Java Code and Code Completion
Refactoring
Eclipse and Android
Preventing Bugs and Keeping Your Code Clean
Static Analyzers
Applying Static Analysis to Android Code
Limitations of Static Analysis
Eclipse Idiosyncrasies and Alternatives
6. Effective Java for Android
The Android Framework
The Android Libraries
Extending Android
Organizing Java Source
Concurrency in Android
AsyncTask and the UI Thread
Threads in an Android Process
Serialization
Java Serialization
Parcelable
Classes That Support Serialization
Serialization and the Application Life Cycle
Part II. About the Android Framework
7. Building a View
Android GUI Architecture
The Model
The View
The Controller
Putting It Together
Assembling a Graphical Interface
Wiring Up the Controller
Listening to the Model
Listening for Touch Events
Listening for Key Events
Alternative Ways to Handle Events
Advanced Wiring: Focus and Threading
The Menu
8. Fragments and Multiplatform Support
Creating a Fragment
Fragment Life Cycle
The Fragment Manager
Fragment Transactions
The Compatibility Package
9. Drawing 2D and 3D Graphics
Rolling Your Own Widgets
Layout
Canvas Drawing
Drawables
Bitmaps
Bling
Shadows, Gradients, and Filters
Animation
OpenGL Graphics
10. Handling and Persisting Data
Relational Database Overview
SQLite
The SQL Language
SQL Data Definition Commands
SQL Data Manipulation Commands
Additional Database Concepts
Database Transactions
Example Database Manipulation Using sqlite3
SQL and the Database-Centric Data Model for Android Applications
The Android Database Classes
Database Design for Android Applications
Basic Structure of the SimpleVideoDbHelper Class
Using the Database API: MJAndroid
Android and Social Networking
The Source Folder (src)
Loading and Starting the Application
Database Queries and Reading Data from the Database
Modifying the Database
Part III. A Skeleton Application for Android
11. A Framework for a Well-Behaved Application
Visualizing Life Cycles
Visualizing the Activity Life Cycle
Visualizing the Fragment Life Cycle
The Activity Class and Well-Behaved Applications
The Activity Life Cycle and the User Experience
Life Cycle Methods of the Application Class
A Flowing and Intuitive User Experience Across Activities
Multitasking in a Small-Screen Environment
Tasks and Applications
Specifying Launch and Task Behavior
12. Using Content Providers
Understanding Content Providers
Implementing a Content Provider
Browsing Video with Finch
Defining a Provider Public API
Defining the CONTENT_URI
Creating the Column Names
Declaring Column Specification Strings
Writing and Integrating a Content Provider
Common Content Provider Tasks
File Management and Binary Data
Android MVC and Content Observation
A Complete Content Provider: The SimpleFinchVideoContentProvider
Code
The SimpleFinchVideoContentProvider Class and Instance Variables
Implementing the onCreate Method
Implementing the getType Method
Implementing the Provider API
Determining How Often to Notify Observers
Declaring Your Content Provider
13. Exploring Content Providers
Developing RESTful Android Applications
A “Network MVC”
Summary of Benefits
Code Example: Dynamically Listing and Caching YouTube
Video Content
Structure of the Source Code for the Finch YouTube Video Example
Stepping Through the Search Application
Step 1: Our UI Collects User Input
Step 2: Our Controller Listens for Events
Step 3: The Controller Queries the Content Provider with a managedQuery
on the Content Provider/Model
Step 4: Implementing the RESTful Request
Constants and Initialization
Creating the Database
A Networked Query Method
insert and ResponseHandlers
File Management: Storing Thumbnails
14. Multimedia
Audio and Video
Playing Audio and Video
Audio Playback
Video Playback
Recording Audio and Video
Audio Recording
Video Recording
Stored Media Content
15. Location and Mapping
Location-Based Services
Mapping
The Google Maps Activity
The MapView and MapActivity
Working with MapViews
MapView and MyLocationOverlay Initialization
Pausing and Resuming a MapActivity
Controlling the Map with Menu Buttons
Controlling the Map with the Keypad
Location Without Maps
The Manifest and Layout Files
Connecting to a Location Provider and Getting Location Updates
Updating the Emulated Location
16. Sensors, NFC, Speech, Gestures, and Accessibility
Sensors
Position
Other Sensors
Near Field Communication (NFC)
Reading a Tag
Writing to a Tag
P2P Mode
Gesture Input
Accessibility
17. Communication, Identity, Sync, and Social Media
Account Contacts
Authentication and Synchronization
Authentication
Synchronization
Bluetooth
The Bluetooth Protocol Stack
Bluez: The Linux Bluetooth Implementation
Using Bluetooth in Android Applications
18. The Android Native Development Kit (NDK)
Native Methods and JNI Calls
Conventions on the Native Method Side
Conventions on the Java Side
The Android NDK
Setting Up the NDK Environment
Compiling with the NDK
JNI, NDK, and SDK: A Sample App
Android-Provided Native Libraries
Building Your Own Custom Library Modules
Native Activities
Index