Home > Store

Android for Programmers: An App-Driven Approach

Register your product to gain access to bonus material or receive a coupon.

Android for Programmers: An App-Driven Approach


  • Sorry, this book is no longer in print.
Not for Sale



  • The application-driven approach to Android: brings the Deitels' signature "Live Code" technique to Android development!
  • Teaches every new technique in the context of a real-world Android App: 16 complete Apps in all, covering a broad spectrum of Android 2.x APIs!
  • Shows how to use Eclipse and Android Development Tools (ADT) for Eclipse to create, debug, and deploy Apps
  • By the world's #1 Java programming authors, and the creators of the best-selling iPhone for Programmers
  • Power Point Slides available for course use


  • Copyright 2012
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-212136-0
  • ISBN-13: 978-0-13-212136-1

The professional programmer’s Deitel® guide to Android™ smartphone and tablet app development and the Eclipse IDE with the Android Development Tools (ADT) plug-in

Billions of apps have been downloaded from Android Market! This book gives you everything you’ll need to start developing great Android apps quickly and getting them published on Android Market. The book uses an app-driven approach—each new technology is discussed in the context of 16 fully tested Android apps, complete with syntax coloring, code walkthroughs and sample outputs. Apps you’ll develop include:

  • SpotOn Game
  • Slideshow
  • Flag Quiz
  • Route Tracker
  • Favorite Twitter® Searches
  • Address Book
  • Tip Calculator
  • Doodlz
  • Weather Viewer
  • Cannon Game
  • Voice Recorder
  • Pizza Ordering 

Practical, example-rich coverage of:

  • Smartphone and Tablet Apps, Android Development Tools (ADT) Plug-In for Eclipse
  • Activities, Intents, Content Providers
  • GUI Components, Menus, Toasts, Resource Files, Touch and Gesture Processing
  • Tablet Apps, ActionBar and AppWidgets
  • Tweened Animations, Property Animations
  • Camera, Audio, Video, Graphics, OpenGL ES
  • Gallery and Media Library Access
  • SharedPreferences, Serialization, SQLite
  • Handlers and Multithreading, Games
  • Google Maps, GPS, Location Services, Sensors
  • Internet-Enabled Apps, Web Services, Telephony, Bluetooth®
  • Speech Synthesis and Recognition
  • Android Market, Pricing, Monetization
  • And more…

PLUS:  Register your product at www.informit.com/register for additional online chapters that cover Android Ice Cream Sandwich (Android 4), including a complete, working Ice Cream Sandwich app!


  • For information on Deitel’s Dive Into® Series instructor-led programming language training courses offered at customer sites worldwide visit www.deitel.com/training or write to deitel@deitel.com
  • Download code examples
  • Check out the growing list of programming Resource Centers
  • Join the Deitel Twitter (@deitel) and Facebook (www.facebook.com/DeitelFan) communities
  • To receive updates for this book, subscribe to the free Deitel ® Buzz Online e-mail newsletter at www.deitel.com/newsletter/subscribe.html

Sample Content

Online Sample Chapter

Android for Programmers Welcome App: Dive-Into Eclipse and the ADT Plugin

Sample Pages

Download the sample pages (includes Chapter 3 and Index)

Table of Contents

Preface xiv

Before You Begin xxii

Chapter 1: Introduction to Android 1

1.1 Introduction 2

1.2 Android Overview 4

1.3 Android 2.2 (Froyo) 7

1.4 Android 2.3 (Gingerbread) 10

1.5 Android 3.0 (Honeycomb) 12

1.6 Android Ice Cream Sandwich 15

1.7 Downloading Apps from the Android Market 16

1.8 Packages 17

1.9 Android Software Development Kit (SDK) 18

1.10 Object Technology: A Quick Refresher 20

1.11 Test-Driving the Doodlz App in an Android Virtual Device (AVD) 23

1.12 Deitel Resources 32

1.13 Android Development Resources 33

1.14 Wrap-Up 34

Chapter 2: Android Market and App Business Issues 35

2.1 Introduction 36

2.2 Building Great Android Apps 36

2.3 Android Best Practices 38

2.4 Registering at Android Market 44

2.5 Setting Up a Google Checkout Merchant Account 44

2.6 AndroidManifest.xml File 45

2.7 Preparing Your Apps for Publication 46

2.8 Uploading Your Apps to Android Market 51

2.9 Other Android App Marketplaces 54

2.10 Pricing Your App: Free or Fee 54

2.11 Monetizing Apps with In-App Advertising 56

2.12 Monetizing Apps: Using In-App Billing to Sell Virtual Goods in Your Apps 57

2.13 Launching the Market App from Within Your App 59

2.14 Managing Your Apps in Android Market 59

2.15 Marketing Your App 59

2.16 Other Popular App Platforms 64

2.17 Android Developer Documentation 65

2.18 Android Humor 66

2.19 Wrap-Up 67

Chapter 3: Welcome App 68

Dive-Into® Eclipse and the ADT Plugin

3.1 Introduction 69

3.2 Technologies Overview 69

3.3 Eclipse IDE 70

3.4 Creating a New Project 71

3.5 Building the Welcome App’s GUI with the ADT’s Visual Layout Editor 74

3.6 Examining the main.xml File 87

3.7 Running the Welcome App 89

3.8 Wrap-Up 89

Chapter 4: Tip Calculator App 91

Building an Android App with Java

4.1 Introduction 92

4.2 Test-Driving the Tip Calculator App 93

4.3 Technologies Overview 94

4.4 Building the App’s GUI 94

4.5 Adding Functionality to the App 106

4.6 Wrap-Up 116

Chapter 5: Favorite Twitter® Searches App 117

SharedPreferences, Buttons, Nested Layouts, Intents, AlertDialogs, Inflating XML Layouts and the Manifest File

5.1 Introduction 118

5.2 Test-Driving the Favorite Twitter Searches App 119

5.3 Technologies Overview 121

5.4 Building the App’s GUI and Resource Files 123

5.5 Building the App 131

5.6 AndroidManifest.xml 142

5.7 Wrap-Up 143

Chapter 6: Flag Quiz Game App 146

Assets, AssetManager, Tweened Animations, Handler, Menus and Logging Error Messages

6.1 Introduction 147

6.2 Test-Driving the Flag Quiz Game App 151

6.3 Technologies Overview 151

6.4 Building the App’s GUI and Resource Files 153

6.5 Building the App 160

6.6 AndroidManifest.xml 174

6.7 Wrap-Up 175

Chapter 7: Cannon Game App 176

Listening for Touches and Gestures, Manual Frame-By-Frame Animation, Graphics, Sound, Threading, SurfaceView and SurfaceHolder

7.1 Introduction 177

7.2 Test-Driving the Cannon Game App 178

7.3 Technologies Overview 179

7.4 Building the App’s GUI and Resource Files 181

7.5 Building the App 183

7.6 Wrap-Up 203

Chapter 8: SpotOn Game App 204

Property Animation, ViewPropertyAnimator, AnimatorListener, Thread-Safe Collections, Default SharedPreferences for an Activity

8.1 Introduction 205

8.2 Test-Driving the SpotOn Game App 206

8.3 Technologies Overview 207

8.4 Building the App’s GUI and Resource Files 208

8.5 Building the App 210

8.6 Wrap-Up 224

Chapter 9: Doodlz App 225

Two-Dimensional Graphics, SensorManager, Multitouch Events and Toasts

9.1 Introduction 226

9.2 Test-Driving the Doodlz App 227

9.3 Technologies Overview 228

9.4 Building the App’s GUI and Resource Files 229

9.5 Building the App 234

9.6 Wrap-Up 256

Chapter 10: Address Book App 258

ListActivity, AdapterViews, Adapters, Multiple Activities, SQLite, GUI Styles, Menu Resources and MenuInflater

10.1 Introduction 259

10.2 Test-Driving the Address Book App 261

10.3 Technologies Overview 262

10.4 Building the GUI and Resource Files 263

10.5 Building the App 269

10.6Wrap-Up 290

Chapter 11: Route Tracker App 291

Google Maps API, GPS, LocationManager, MapActivity, MapView and Overlay

11.1 Introduction 292

11.2 Test-Driving the Route Tracker App 294

11.3 Technologies Overview 296

11.4 Building the GUI and Resource Files 298

11.5 Building the App 300

11.6 Wrap-Up 318

Chapter 12: Slideshow App 319

Gallery and Media Library Access, Built-In Content Providers, MediaPlayer, Image Transitions, Custom ListActivity Layouts and the View-Holder Pattern

12.1 Introduction 320

12.2 Test-Driving the Slideshow App 323

12.3 Technologies Overview 324

12.4 Building the GUI and Resource Files 327

12.5 Building the App 331

12.6 Wrap-Up 358

Chapter 13: Enhanced Slideshow App 360

Serializing Data, Taking Pictures with the Camera and Playing Video in a VideoView

13.1 Introduction 361

13.2 Test-Driving the Enhanced Slideshow App 362

13.3 Technologies Overview 363

13.4 Building the GUI and Resource Files 364

13.5 Building the App 367

13.6 Wrap-Up 389

Chapter 14: Weather Viewer App 390

Web Services, JSON, Fragment, ListFragment, DialogFragment, ActionBar, Tabbed Navigation, App Widgets, Broadcast Intents and BroadcastReceivers

14.1 Introduction 391

14.2 Test-Driving the Weather App 393

14.3 Technologies Overview 394

14.4 Building the App’s GUI and Resource Files 396

14.5 Building the App 399

14.6 Wrap-Up 459

Index 460

Chapters on the Web

Go to the book’s registration page  to register and download these chapters.

Chapter 15: PHAB’s Pizza App

Text-to-Speech, Speech-to-Text and Telephony

Chapter 16: Voice Recorder App

Audio Recording and Playback

Chapter 17: Enhanced Address Book App


Chapter 18: 3D Art App

OpenGL ES 3D Rendering

Chapter 19: HTML5 Favorite Twitter® Searches App

Bonus Chapter: HTML5, CSS3 and JavaScript for Experienced Web Developers


Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020