Hello, Android
Introducing Googles Mobile Development Platform, Fourth Edition
by Ed Burnette
Version: P1.0 (May 2015)
Copyright 2015 The Pragmatic Programmers, LLC. This book is licensed to the individual who purchased it. We don't copy-protect it because that would limit your ability to use it for your own purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copy with other members of your team, with friends, or via file sharing services. Thanks.
Dave & Andy.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
The team that produced this book includes:
Susannah Davidson Pfalzer (editor)
Potomac Indexing, LLC (indexer)
Liz Welch (copyeditor)
Dave Thomas (typesetter)
Janet Furlow (producer)
Ellie Callahan (support)
For international rights, please contact .
For the Best Reading Experience...
We strongly recommend that you read this book with the publisher defaults setting enabled for your reading device or application. Certain formats and characters may not display correctly without this setting. Please refer to the instructions for your reader on how to enable the publisher defaults setting.
Table of Contents
Copyright 2015, The Pragmatic Bookshelf.
What Readers Are Saying About the Fourth Edition of Hello, Android
Once again, Ed has created a very smart guide for beginner and intermediate Android developers. Its a practical, highly readable guide whether you are just entering the world of Android application development, or if you have some experience but want to dive more deeply into concepts like basic game creation, animations, sound effects, threading, databases, and Google Play Services.
Diego Torres Milano |
Geek, Android system engineer, Linux advocate, and author |
For a quick dip in the Android app development waters, its tough tobeat this updated version of the original book on the subject!
Mark Murphy |
Founder, CommonsWare and author of The Busy Coders Guide to Android Development |
Hello, Android concisely covers a lot of ground with engaging examples and an enjoyable writing style. I recommend this book to anyone who wants to ramp up quickly in Android development.
Jason Pike |
Software developer, theswiftlearner.com |
The chapter on the Play Store was a wake-up call, showing howeasy it is to get an app on there, in comparison with the fruity app store.
Stephen Wolff |
Director, Max Gate Digital Ltd. |
Acknowledgments
Id like to thank the many people who made this book possible, including the readers of the previous editions for all their great suggestions; my editor, Susannah Pfalzer, for her attention to detail; Craig Castelaz, Javier Collado, Eric Hung, Edward Ingram, Chris Johnson, Howard Koslow, Helen Li, Irakli Nadareishvili, Jan Nonnen, Jason Pike, Mike Riley, Sam Rose, Loren Sands-Ramshaw, Carlos Santana, Charley Stran, and Stephen Wolff for providing valuable review comments; and especially Lisa, Chris, and Michael, for their continued patience and support.
Copyright 2015, The Pragmatic Bookshelf.
Preface
Android is an open source operating system for mobile phones and tablets that was created by Google and its partners and contributors. Its inside over a billion cell phones and other mobile devices, making Android the #1 platform for application developers. Whether youre a hobbyist or a professional programmer, whether youre doing it for fun or for profit, you need to learn more about developing for Android. This book will help you get started.
What Makes Android Special?
Many other mobile platforms are available on the market today, including iOS, Windows, Tizen, Firefox OS, and more. So why do people choose Android over the others? Whats the difference?
Although some of its features have appeared before, Android is the first environment that combines the following:
An open, free development platform based on Linux and open source: Handset makers like it because they can use and customize the platform without paying a royalty. Developers like it because they know that the platform has legs and is not locked into any one vendor that may go under or be acquired.
A component-based architecture inspired by Internet mashups: Parts of one application can be used in ways not originally envisioned by the developer. You can even replace built-in components with your own improved versions. This has unleashed a new round of creativity in the mobile space.
Tons of services out of the box: Location-based services use GPS or cell tower triangulation to allow you to customize the user experience depending on where you are. A full-powered SQL database lets you harness the power of local storage for occasionally connected computing and synchronization. Browser and map views can be embedded directly in your applications. All these capabilities help raise the bar on functionality while lowering your development costs.
Automatic management of the application life cycle: Programs are isolated from each other by multiple layers of security, which provide a high level of system stability. The end user doesnt have to worry about what applications are active or close some programs so that others can run. Android is optimized for low-power, low-memory devices in a fundamental way that no previous platform has attempted.
High-quality graphics and sound: Smooth, antialiased 2D and 3D-accelerated graphics have enabled new kinds of games and business applications. Codecs for the most common industry-standard audio and video formats are built right in, including H.264 (AVC), MP3, and AAC.
Portability across a wide range of current and future hardware: All your programs are written in Java and executed by Androids ART ahead-of-time compiler or Dalvik virtual machine, so your code will be portable across ARM, x86, and other architectures. Support for a variety of input methods is included, such as keyboards, game pads, touch, TV remotes, mice, and trackballs. User interfaces can be customized for any screen resolution and orientation.
Android offers a fresh take on the way mobile applications interact with users, along with the technical underpinnings to make it possible. But the best part of Android is the software that youre going to write for it. This book will help you get off to a great start.