Android For Programmers: An App-driven Approach by Paul DeitelAndroid For Programmers: An App-driven Approach by Paul Deitel

Android For Programmers: An App-driven Approach

byPaul Deitel, Harvey Deitel, Abbey Deitel

Paperback | December 27, 2013

Pricing and Purchase Info

$35.37 online 
$46.99 list price
Earn 177 plum® points

Prices and offers may vary in store

Out of stock online

Available in stores


The professional programmer’s Deitel® guide to smartphone and tablet app development using Android 4.3 and 4.4, the Eclipse-based Android Development Tools and the new Android Studio


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

  • Welcome App
  • Cannon Game
  • Tip Calculator
  • Doodlz
  • Twitter® Searches
  • Address Book
  • Flag Quiz

The first-generation Android phones were released in October 2008. By October 2013, a Strategy Analytics report showed that Android had 81.3% of the global smartphone market share, compared to 13.4% for Apple, 4.1% for Microsoft and 1% for Blackberry ( Billions of apps have been downloaded from Google Play. There are now more than one billion activated Android devices worldwide and more than 1.5 million Android devices are being activated daily ( The opportunities for Android app developers are enormous.


This book presents leading-edge computing technologies for professional software developers. At the heart of the book is the Deitel “app-driven approach”–concepts are presented in the context of complete working Android apps, rather than using code snippets. The introduction and app test drives at the beginning of each chapter show one or more sample executions. The book’s source code is available at


The apps in this book were carefully designed to introduce you to key Android features and APIs. You’ll quickly learn everything you need to start building Android apps–beginning with a testdrive of the Doodlz app in Chapter 1, then building your first app in Chapter 2. By the time you reach Chapter 9, you’ll be ready to create your own apps for submission to Google Play and other app marketplaces. You’ll master the Google Play submission process, including uploading your apps, deciding whether to sell your apps or offer them for free, and marketing them using in-app advertising, social media, Internet public relations and more.


Practical, example-rich coverage of:

  • Android 4.3 and 4.4
  • Android Development Tools, Android Studio
  • Supporting Various Screen Sizes/Resolutions
  • Accessibility, Internationalization, Graphics
  • Activities, Fragments, Intents, Preferences
  • GUIs, Layouts, Menus, Resource Files, Lists, Adapters, Events, Touch/Gesture Processing
  • Immersive Mode, Printing Framework, PrintHelper
  • Assets (Images, Audio), View Animation
  • Threading, Collections, SQLite Database
  • Social sharing via implicit intents
  • Google Play™, App Publishing, Pricing, Monetization, Marketing, In-App Advertising, In-App Billing and more.



  • Download code examples
  • For information on Deitel’s Dive Into® Series programming training courses delivered at organizations worldwide visit or write to
  • Join the Deitel social networking communities on Facebook® at, Twitter® @deitel, Google+ at, LinkedIn® at, YouTube at and subscribe to the Deitel® Buzz Online e-mail newsletter at subscribe.html


The Deitel® Developer Series is designed for professional programmers. The series presents focused treatments on a growing list of emerging and mature technologies, including Android™ app development, iOS® app development, Java, C# and .NET, C++, C, JavaScript®, Internet and web development and more. Each book in the series contains the same live-code teaching methodology used in the Deitels’ How to Program Series college textbooks–most concepts are presented in the context of completely coded, working apps.

Deitel & Associates is an internationally recognized authoring and corporate training organization specializing in Android and iOS® app development, programming languages, object technology and Internet and web software technology. The company offers instructor-led courses delivered at client sites worldwide on programming languages and platforms, such as Android™ app development, iOS® app development, Java, Objective-C, C#, Visual Basic®, Visual C++®, C++, C, XML, Python, Perl®, object technology, Internet and web programming, and a growing list of additional programming and software-development courses. The founders of Deitel & Associates, Inc., are Paul Deitel and Dr. Harvey Deitel. The company’s training clients include many of the world’s largest corporations, government agencies, branches of the military and academic institutions. To learn more about Deitel & Associates, Inc., its professional books, college textbooks, e-books and LiveLessons video training, and its worldwide Dive-Into® Series instructor-led, on-site training curriculum, visit or send an email to Join the Deitel social media communities on Facebook® (, Twitter® (@deitel), Google+ (, LinkedIn® ( and YouTube (, and subscribe to the Deitel® Buzz Online newsletter (


Paul Deitel, Abbey Deitel and Harvey Deitel are from Deitel & Associates, Inc., the internationally recognized programming languages authoring and corporate training organization. Millions of people worldwide have used Deitel books, LiveLessons video training and online resource centers to master Android™ app development, iOS® app dev...
Title:Android For Programmers: An App-driven ApproachFormat:PaperbackDimensions:368 pages, 9.12 × 7 × 0.71 inPublished:December 27, 2013Publisher:Pearson EducationLanguage:English

The following ISBNs are associated with this title:

ISBN - 10:0133570924

ISBN - 13:9780133570922


Table of Contents

Preface xiv

Before You Begin xxiii


Chapter 1: Introduction to Android                  1

1.1 Introduction   2

1.2 Android–The World’s Leading Mobile Operating System   3

1.3 Android Features   3

1.4 Android Operating System   7

1.5 Downloading Apps from Google Play   11

1.6 Packages   12

1.7 Android Software Development Kit (SDK)   13

1.8 Object-Oriented Programming: A Quick Refresher   16

1.9 Test-Driving the Doodlz App in an Android Virtual Device (AVD)   19

1.10 Building Great Android Apps   30

1.11 Android Development Resources   32

1.12 Wrap-Up   34


Chapter 2: Welcome App          35

2.1 Introduction   36

2.2 Technologies Overview   37

2.3 Creating an App   38

2.4 Android Developer Tools Window   44

2.5 Building the App’s GUI with the Graphical Layout Editor   48

2.6 Running the Welcome App   56

2.7 Making Your App Accessible   57

2.8 Internationalizing Your App   59

2.9 Wrap-Up   63


Chapter 3: Tip Calculator App         64

3.1 Introduction   65

3.2 Test-Driving the Tip Calculator App   66

3.3 Technologies Overview   67

3.4 Building the App’s GUI   70

3.5 Adding Functionality to the App   79

3.6 AndroidManifest.xml   87

3.7 Wrap-Up   88


Chapter 4: Twitter® Searches App           89

4.1 Introduction   90

4.2 Test-Driving the App   91

4.3 Technologies Overview   97

4.4 Building the App’s GUI   100

4.5 Building the MainActivity Class   109

4.6 AndroidManifest.xml   124

4.7 Wrap-Up   124


Chapter 5: Flag Quiz App         125

5.1 Introduction   126

5.2 Test-Driving the Flag Quiz App   128

5.3 Technologies Overview   132

5.4 Building the GUI and Resource Files   136

5.5 MainActivity Class   147

5.6 QuizFragment Class   153

5.7 SettingsFragment Class   165

5.8 SettingsActivity Class   166

5.9 AndroidManifest.xml   166

5.10 Wrap-Up   167


Chapter 6: Cannon Game App           168

6.1 Introduction   169

6.2 Test-Driving the Cannon Game App   171

6.3 Technologies Overview   171

6.4 Building the App’s GUI and Resource Files   173

6.5 Class Line Maintains a Line’s Endpoints   175

6.6 MainActivity Subclass of Activity   176

6.7 CannonGameFragment Subclass of Fragment   176

6.8 CannonView Subclass of View   178

6.9 Wrap-Up   196


Chapter 7: Doodlz App        198

7.1 Introduction   199

7.2 Technologies Overview   201

7.3 Building the App’s GUI and Resource Files   203

7.4 MainActivity Class   211

7.5 DoodleFragment Class   212

7.6 DoodleView Class   219

7.7 ColorDialogFragment Class   231

7.8 LineWidthDialogFragment Class   234

7.9 EraseImageDialogFragment Class   238

7.10 Wrap-Up   239


Chapter 8: Address Book App          241

8.1 Introduction   242

8.2 Test-Driving the Address Book App  245

8.3 Technologies Overview   245

8.4 Building the GUI and Resource Files   247

8.5 MainActivity Class   255

8.6 ContactListFragment Class   261

8.7 AddEditFragment Class   268

8.8 DetailsFragment Class   274

8.9 DatabaseConnector Utility Class   282

8.10 Wrap-Up   287


Chapter 9: Google Play and App Business Issues          289

9.1 Introduction   290

9.2 Preparing Your Apps for Publication   290

9.3 Pricing Your App: Free or Fee   295

9.4 Monetizing Apps with In-App Advertising   297

9.5 Monetizing Apps: Using In-App Billing to Sell Virtual Goods   298

9.6 Registering at Google Play   299

9.7 Setting Up a Google Wallet Merchant Account   300

9.8 Uploading Your Apps to Google Play   301

9.9 Launching the Play Store from Within Your App   302

9.10 Managing Your Apps in Google Play   303

9.11 Other Android App Marketplaces   303

9.12 Other Popular Mobile App Platforms   303

9.13 Marketing Your Apps   304

9.14 Wrap-Up   308


Index         310


Editorial Reviews

“I really love what you’re doing with the book. It has the potential to become the best Android book on the market. It’s impressive to see so many well-explained useful examples of Android patterns.” –Dan Galpin, Android Advocate and author of Intro to Android Application Development   “I wish this book had been around when I started developing on Android. I haven’t seen any other books cover app publishing so well and the links provided throughout are an impressive collection. You get full applications that show multiple parts of the APIs working together.” –Douglas Jones, Senior Software Engineer, Fullpower Technologies   “By far, this is the quickest way to get comfortable writing applications for the #1 mobile operating system. I really enjoy the book. While the target of Android for Programmers is people with some development experience, even novices will find this book an interesting read and it will speed their immersion into Android development. The book starts by describing the Android development environment. Then each chapter introduces a core aspect of the Android platform by briefly explaining the topic, then illustrating the capability with working code. The sample apps demonstrate the topics of each chapter, which easily can be applied to your own projects.”  –Eric J. Bowden, COO, Safe Driving Systems, LLC   “Teaches you the Android SDK through actual use. Shows you how to write an app in every chapter, explaining each aspect of the SDK as it’s encountered. Whether you’ve never touched Android or you have some apps under your belt already, this book is definitely worth picking up.” –Ian G. Clifton, Independent Contractor and Android App Developer   “The updates in the second edition truly add value. The authors captured the right mix of Android enhancements and masterfully wove them into solid, practical apps. Great job!” –Chuck Lasky, Northern Virginia Community College   “An excellent book for someone who has done Java development and wants to learn Android through examples–developers can quickly pick up Android development skills. The app-driven approach is unique–at the end of each chapter, you have a well-designed and functioning app! The technical depth is excellent.” –Arijit Sengupta, Wright State University   “The ‘Characteristics of Great Apps’ table is excellent. The authors present the goals of each app and provide an opportunity to test-drive it before describing its implementation.”  –Jesus Ubaldo Quevedo-Torrero, University of Wisconsin–Parkside   “Addresses a compelling set of topics in a fun and instructive way. Creates UI/layouts with a depth I’ve not seen elsewhere. The Flag Quiz app is enjoyable–View animation adds a professional touch; clear description of key UI elements. The Address Book chapter is a good introduction to CRUD-type apps.” –Sebastian Nykopp, Chief Architect, Reaktor   “The Welcome app looks solid; great to see the integration of the layout editor. The Tip Calculator app is pretty cool; I love the deeper coverage of the lifecycle. The Favorite Twitter Searches app is a good way to demonstrate ScrollView. The Flag Quiz app is one of my favorites, covering delayed events, View animations and string arrays; I like the use of the AssetManager for the flags. The XML declaration and explanation of the tweened flag-shake animation are nicely done. Nice job of keeping the database queries out of the UI thread in the Address Book app.” –Dan Galpin, Android Advocate and author of Intro to Android Application Development   “Great job illustrating the Visual Layout Editor; I liked the approach of creating a project then building visual components without code; this makes it easy to experiment with other properties to customize the look of the app. The line-by-line explanations of the code are extremely valuable; this is a solid introduction to how Android works. Favorite Twitter Searches taught me things I didn’t know. The Flag Quiz app is a great chapter. The Cannon Game app is a nice introduction to animation. The Doodlz app chapter uses great examples to illustrate the different concepts. The Address Book app is a good introduction to database access on the Android platform that presents the structures required for SQLite databases.”–Eric J. Bowden, COO, Safe Driving Systems, LLC   “The Technologies Overviews are particularly nice. The Intro chapter gives a solid overview of Android. The Welcome app chapter is a nice intro to layouts, keeping it simple, while still using a common layout (RelativeLayout). Favorite Twitter Searches is a great chapter that introduces a lot of core concepts. App descriptions give a clear understanding of what’s being built; the code highlighting is helpful. Doodlz is a great app–anyone can identify with it. The Address Book app is a good intro to launching other Activities and utilizing a SQLite database.”–Ian G. Clifton, Independent Contractor and Android App Developer   “Chapter 1 is an easy introduction; thanks to the link to one of the blogs, I found an alternate emulator. Welcome App shows layouts and some controls and prepares the way for resource internationalization. The Tip Calculator app UI highlights all the tricky cases of TableLayout and TableRow, which makes it a valuable demonstration. The Favorite Twitter Searches app does a good job of introducing a number of important UI skills, especially using the LayoutInflater and the ScrollView to programmatically add UI elements. Flag Quiz uses a variety of tools, such as collections, AlertDialog.Builder and animations. I like the configuration check for screen size to set the orientation of the Doodlz app. I haven’t seen any other books cover app publishing so well.” –Douglas Jones, Senior Software Engineer, Fullpower Technologies   “Good Intro to overall Android, Java and OO concepts.”–Ronan ‘‘Zero’’ Schwarz, CIO, OpenIntents   “One of the best Android books. Does an excellent job explaining the Android platform; I love the car analogy to explain object-oriented terms. Tip Calculator does a good job showing how to create a GUI–I like using the Outline window. I’ve never published an app, but after seeing how easy it is, I have a couple that I’m considering publishing.” –Tony Cantrell, Georgia Northwestern Technical College   “The Flag Quiz is interesting, engaging and shows important concepts like fragments, animations and resource qualifiers. The Cannon Game is fun–a great way to demonstrate displaying moving objects on the screen.” –Arijit Sengupta, Wright State University   “By the end of each chapter the reader will have created a functional app while acquiring a working knowledge of the material. This is the most practical method to master app development. The Twitter Searches app is a great example to illustrate arrays, opening a website, creating key-value pairs, hiding the keyboard and interacting with the app.” –Dawn Wick, Southwestern Community College   “Apps use Android 4.4 KitKat features, like printing and immersive mode. Covers the details a developer needs to be successful. The Welcome App chapter is very good; creating the project with no code is nice. I like that Twitter Searches uses the web to connect the user to Twitter. The Cannon Game brings the basic elements together for a game–animation, sounds, etc.” –Jim Hathaway, Application Developer, Kellogg Company   “I really like how accessibility is covered; this is generally an afterthought for most developers. Chapter 9 contains useful information that’s hard to find, particularly in respect to marketing–this is something that developers struggle to discover.” –Michael Pardo, Mobiata   “Nice discussion of intents and how these are needed to start activities. Cannon Game is challenging, but well implemented and explained. Chapter 9, Google Play and App Business Issues, is perfect–the information about market shares and tools to convert Android apps into iOS apps is very motivating.” –Jesus Ubaldo Quevedo-Torrero, University of Wisconsin—Parkside