Table Of ContentAndroid™ Application Development For Dummies®, 3rd Edition
Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030 5774,
www.wiley.com
Copyright © 2015 by John Wiley & Sons, Inc., Hoboken, New Jersey
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any
form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise,
except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without
the prior written permission of the Publisher. Requests to the Publisher for permission should be
addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken,
NJ 07030, (201) 748 6011, fax (201) 748 6008, or online at
http://www.wiley.com/go/permissions.
Portions of this page are based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything
Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc.
and may not be used without written permission. Android is a trademark of Google, Inc. All other
trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated
with any product or vendor mentioned in this book.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE
AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO
THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND
SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT
LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO
WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL
MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE
SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE
UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING
LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF
PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT
PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR
THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE
FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK
AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION
DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE
INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR
RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE
THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR
DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS
READ.
For general information on our other products and services, please contact our Customer Care
Department within the U.S. at 877 762 2974, outside the U.S. at 317 572 3993, or fax 317 572
4002. For technical support, please visit www.wiley.com/techsupport.
Wiley publishes in a variety of print and electronic formats and by print on demand. Some
material included with standard print versions of this book may not be included in e books or in
print on demand. If this book refers to media such as a CD or DVD that is not included in the
version you purchased, you may download this material at http://booksupport.wiley.com.
For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2014954664
Android™ Application Development For
Dummies®
Visit www.dummies.com/cheatsheet/androidappdevelopment to
view this book's cheat sheet.
Table of Contents
Cover
Introduction
About This Book
Conventions Used in This Book
Foolish Assumptions
How This Book Is Organized
Icons Used in This Book
Beyond the Book
Part I: Getting Started with Your First Android Application
Chapter 1: Developing Spectacular Android Applications
Why Develop for Android?
Android Development Basics
Hardware Tools
Software Tools
Chapter 2: Prepping Your Development Headquarters
Developing the Android Developer Inside You
Assembling Your Toolkit
Tuning Up Your Hardware
Installing and Configuring Your Support Tools
Installing Android Studio
Installing Java 7
Adding SDK Packages
Navigating the Android SDK
Specifying Android Platforms
Using SDK Tools for Everyday Development
Part II: Building and Publishing Your First Application
Chapter 3: Your First Android Project
Starting a New Project in Android Studio
Responding to Errors
Setting Up an Emulator
Running the Hello Android App
Understanding Project Structure
Chapter 4: Creating the User Interface
Creating the Silent Mode Toggle Application
Laying Out the Application
Adding an Image to Your Application
Creating a Launcher Icon for the Application
Previewing the Application in the Visual Designer
Chapter 5: Coding Your Application
Understanding Activities and the Activity Lifecycle
Creating Your First Activity
Working with the Android Framework Classes
Installing Your Application
Material Design
UhOh! (Responding to Errors)
Thinking Beyond the Application Boundaries
Chapter 6: Understanding Android Resources
Understanding Resources
Working with Resources
Different Strokes for Different Folks: Using Resource Qualifier Directories
Chapter 7: Turning Your Application into an App Widget
Working with App Widgets in Android
Working with Intents and Pending Intents
Creating the App Widget
Placing Your Widget on the Home Screen
Chapter 8: Publishing Your App to the Google Play Store
Creating a Distributable File
Creating a Google Play Developer Profile
Pricing Your Application
Getting Screen Shots for Your Application
Uploading Your Application to the Google Play Store
Watching the Number of Installs Soar
Part III: Creating a Feature Rich Application
Chapter 9: Designing the Tasks Application
Reviewing the Basic Requirements
Creating the Application’s Screens
Chapter 10: Creating the Task Detail Page
Creating the TaskEditActivity
Creating the TaskEditActivity
Linking the List View to the Edit View
Creating the TaskEditFragment
You Put the Fragment in the Activity and Shake It All Up
Updating the Styles
A Special Bonus
Chapter 11: Going a la Carte with Your Menu
Understanding Options and Context Menus
Creating Your First Menu
Creating a LongPress Action
Chapter 12: Handling User Input
Creating the User Input Interface
Getting Choosy with Dates and Times
Creating an Alert Dialog
Validating Input
Chapter 13: Getting Persistent with Data Storage
Finding Places to Put Data
Understanding How the SQLite ContentProvider Works
Creating Your Application’s SQLite Database
Using ContentProvider URIs
Dealing with CRUD
Implementing the Save Button
Implementing the List View
Reading Data into the Edit Page
Chapter 14: Reminding the User
Seeing Why You Need AlarmManager
Asking the User for Permission
Waking Up a Process with AlarmManager
Updating a Notification
Clearing a Notification
Rebooting Devices
Chapter 15: Working with Android Preferences
Understanding the Android Preferences Framework
Understanding the PreferenceFragment Class
Creating Your Preferences Screen
Working with the PreferenceFragment Class
Working with Preferences in Your Activities at Runtime
Part IV: Android Is More than Phones
Chapter 16: Developing for Tablets
Considering the Differences between Phones and Tablets
Tweaking the Tasks App for Tablets
Configuring a Tablet Emulator
Creating a New Product Flavor
Creating an AndroidManifest for Phones
Creating an AndroidManifest for Tablets
Making the TaskListAndEditorActivity for Tablets
Building the Tablet App
Adding the App Callbacks
One More Thing . . .
Chapter 17: Supporting Older Versions of Android
Understanding AppCompat
Updating the build File
Adding the Toolbar
Using the AppCompat Theme
Testing Your App
Working with RighttoLeft Languages
Fixing the Add Task Menu
Fixing the Window Options
Using Newer APIs
Using Android Lint
Chapter 18: Wearing the Tasks App
Preparing Your Development Environment
Creating a New Wear App
Publishing the Data from Your Phone
Running the App without Android Studio
Packaging the App
What’s Next?
Chapter 19: Look Ma, I’m on TV!
Understanding Guidelines for Building TV Apps
Building and Manifesting Changes
Adding the BrowseActivity
Creating the TV Browse Fragment
Creating the CardPresenter
Running Your App
Adding and Editing Items
Creating Backgrounds
Creating More Filters
Chapter 20: Moving beyond Google
Working around Google Features
Setting Up the Fire SDK
Setting Up Your Fire or Emulator
Publishing to Amazon Appstore for Android
Part V: The Part of Tens
Chapter 21: Ten Free Sample Applications and SDKs
Android Samples
The Google I/O App
K9 Mail
GitHub Android App
Facebook SDK for Android
Notepad Tutorial
U+2020
Lollipop Easter Egg
Android Bootstrap
The AOSP
Chapter 22: Ten Tools to Simplify Your Development Life
Android Lint
Android Systrace
RoboGuice and Dagger
Translator Toolkit
Hierarchy Viewer
UI/Application Exerciser Monkey
Git and GitHub
Picasso and OkHttp
Memory Analyzer Tool
Travis ci
About the Author
Cheat Sheet
Connect with Dummies
End User License Agreement
Introduction
Welcome to Android Application Development For Dummies!
When Android was acquired by Google in 2005 (yes, Android was a start up company at one
point), a lot of people didn’t have much interest in it because Google hadn’t yet entered the mobile
space. Fast forward to a few years later, when Google announced its first Android phone: the G1.
It was the start of something huge.
The G1 was the first publicly released Android device. It didn’t match the rich feature set of the
iPhone at the time, but a lot of people believed in the platform. As soon as Donut (Android 1.6)
was released, it was evident that Google was putting some effort into the product. Immediately
after version 1.6 was released, talk of 2.0 was already on the horizon.
Today, we’re on version 5.0 of the Android platform, with no signs that things are slowing down.
Without doubt, this is an exciting time in Android development.
About This Book
Android Application Development For Dummies is a beginner’s guide to developing Android
applications. You don’t need any Android application development experience under your belt to
get started.
The Android platform is a device independent platform, which means that you can develop
applications for various devices. These devices include, but aren’t limited to phones, watches,
tablets, cars, e book readers, netbooks, televisions, and GPS devices.
Finding out how to develop for the Android platform opens a large variety of development options
for you. This book distills hundreds, if not thousands, of pages of Android documentation, tips,
tricks, and tutorials into a short, digestible format that allows you to springboard into your future
as an Android developer. This book isn’t a recipe book, but it gives you the basic knowledge to
assemble various pieces of the Android framework to create interactive and compelling
applications.
Conventions Used in This Book
Throughout the book, you use the Android framework classes, and you’ll create Java classes and
XML files.
Code examples in this book appear in a monospace font so that they stand out from other text in the
book. This means that the code you’ll see looks like this:
public class MainActivity
Java is a high level programming language that is case sensitive, so be sure to enter the text into
the editor exactly as you see it in the book. The examples follow standard Java conventions so you
can transition easily between the book examples and the example code provided by the Android
Description:The updated edition of the bestselling guide to Android app development If you have ambitions to build an Android app, this hands-on guide gives you everything you need to dig into the development process and turn your great idea into a reality! In this new edition of Android App Development For Dum