Table of Contents
Preface
Audience
How This Book Is Organized
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
Rick Rogers
John Lombardo
Zigurd Mednieks
Blake Meike
Part I. Development Kit Walk-Through
Chapter 1. Getting to Know Android
Why Android?
The Open Handset Alliance
The Android Execution Environment
Components of an Android Application
Android Activity Lifecycle
Android Service Lifecycle
How This Book Fits Together
Chapter 2. Setting Up Your Android Development
Environment
Setting Up Your Development Environment
Creating an Android Development Environment
Hello, Android
Where We’re Going
Starting a New Android Application: HelloWorld
Writing HelloWorld
Running HelloWorld
Chapter 3. Using the Android Development Environment for Real
Applications
MicroJobs: This Book’s Main Sample Application
Android and Social Networking
Downloading the MJAndroid Code
A Brief Tour of the MJAndroid Code
The Project Root Folder (MJAndroid)
The Source Folder (src)
The Resource Folder (res)
First Steps: Building and Running the MicroJobs Application
A Very Short Tour of the Android SDK/Eclipse IDE
Loading and Starting the Application
Digging a Little Deeper: What Can Go Wrong?
Running an Application on the T-Mobile Phone
Enable USB debugging on your phone
Load the USB driver for ADB
Connecting the phone
Running MicroJobs on the phone
Summary
Chapter 4. Under the Covers: Startup Code and Resources in the MJAndroid
Application
Initialization Parameters in AndroidManifest.xml
Initialization in MicroJobs.java
More Initialization of MicroJobs.java
Summary
Chapter 5. Debugging Android Applications
The Tools
Eclipse Java Editor
Java Errors
The Debugger
Logcat
Looking at logcat to solve runtime errors
Writing your own logcat entries
Android Debug Bridge (adb)
DDMS: Dalvik Debug Monitor Service
Traceview
Trace data collection
Summary
Chapter 6. The ApiDemos Application
Application Setup in the Manifest File
Finding the Source to an Interesting Example
Custom Title Demo
Linkify Demo
Adding Your Own Examples to ApiDemos
Chapter 7. Signing and Publishing Your
Application
Test Your Application
Attach an End User License Agreement If Desired
Create and Attach an Icon and Label
Clean Up for Release
Version Your Application
Obtaining a Signing Certificate and API Key
Getting a Signing Certificate for an Application You Are Going to Ship
Generating a key pair (public and private keys) and a signing certificate
Getting a Signing Certificate While Debugging
Getting the MD5 fingerprint of your Debug signing certificate
Getting a Map API Key from Google
Signing Your Application
Retesting Your Application
Publishing on Android Market
Signing Up As an Android Developer
Uploading Your Application
Part II. Programming Topics
Chapter 8. Persistent Data Storage: SQLite Databases and Content
Providers
Databases
Basic Structure of the MicroJobsDatabase Class
Reading Data from the Database
Modifying the Database
Inserting data into the database
Updating data already in the database
Deleting data in the database
Content Providers
Introducing NotePad
Activities
Database
Structure of the source code
Content Providers
Implementing a content provider
Consuming a Content Provider
Create data (insert)
Read/query data
Update data
Delete data
Chapter 9. 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
Using geo to update location
Using DDMS to update location
Chapter 10. 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
Chapter 11. A Widget Bestiary
Android Views
TextView and EditText
Button and ImageButton
Adapters and AdapterViews
CheckBoxes, RadioButtons, and Spinners
ViewGroups
Gallery and GridView
ListView and ListActivity
ScrollView
TabHost
Layouts
Frame Layout
LinearLayout
TableLayout
AbsoluteLayout
RelativeLayout
Chapter 12. Drawing 2D and 3D Graphics
Rolling Your Own Widgets
Layout
Measurement
Arrangement
Canvas Drawing
Drawing text
Matrix transformations
Drawables
Bitmaps
Bling
Shadows, Gradients, and Filters
Animation
Transition animation
Background animation
Surface view animation
OpenGL Graphics
Chapter 13. Inter-Process Communication
Intents: Simple, Low-Overhead IPC
Intent Objects Used in Inter-Process Communication
Activity Objects and Navigating the User Interface Hierarchy
Example: An Intent to Pick How We Say “Hello World”
Getting a Result via Inter-Process Communication
Remote Methods and AIDL
Android Interface Definition Language
Classes Underlying AIDL-Generated Interfaces
Implementing the Stub interface
Getting an instance of the remote Proxy object
Publishing an Interface
Android IPC Compared with Java Native Interface (JNI)
What Binder Doesn’t Do
Binder and Linux
Chapter 14. Simple Phone Calls
Quick and Easy Phone Calls
Creating an Example Application to Run the call Method
Embedding the Code Snippet in a Simple Application
Exploring the Phone Code Through the Debugger
Creating an Instance of an Intent
Adding Data to an Instance of an Intent
Initiating a Phone Call
Exception Handling
Android Application-Level Modularity and Telephony
Chapter 15. Telephony State Information and Android Telephony Classes
Operations Offered by the android.telephony Package
Package Summary
Limitations on What Applications Can Do with the Phone
Example: Determining the State of a Call
Android Telephony Internals
Inter-Process Communication and AIDL in the android.internal.telephony Package
The android.internal.telephony Package
The android.internal.telephony.gsm Package
Exploring Android Telephony Internals
Android and VoIP
Appendix. Wireless Protocols
Prehistory
The Dawn of Second Generation (2G) Digital Cellular
Improved Digital Cellular (2.5G)
The Rise of 3G
The Future: 4G
Index