Introduction to Android Application Development, Fourth Edition (2014)
Android is a popular, free, open-source mobile platform that has taken the wireless world by storm. This book provides guidance for software development teams on designing, developing, testing, debugging, and distributing professional Android applications. If you’re a veteran mobile developer, you can find tips and tricks to streamline the development process and take advantage of Android’s unique features. If you’re new to mobile development, this book provides everything you need to make a smooth transition from traditional software development to mobile development—specifically, its most promising platform: Android.
Who Should Read This Book
This book includes tips for successful mobile development based upon our years in the mobile industry and covers everything you need to know in order to run a successful Android project from concept to completion. We cover how the mobile software process differs from traditional software development, including tricks to save valuable time and pitfalls to avoid. Regardless of the size of your project, this book is for you.
This book was written for several audiences:
Software developers who want to learn to develop professional Android applications. The bulk of this book is targeted at software developers with Java experience who do not necessarily have mobile development experience. More-seasoned developers of mobile applications can learn how to take advantage of Android and how it differs from the other technologies on the mobile development market today.
Quality assurance personnel tasked with testing Android applications. Whether they are black-box or white-box testing, quality assurance engineers can find this book invaluable. We devote several chapters to mobile QA concerns, including topics such as developing solid test plans and defect-tracking systems for mobile applications, how to manage handsets, and how to test applications thoroughly using all the Android tools available.
Project managers planning and managing Android development teams. Managers can use this book to help plan, hire for, and execute Android projects from start to finish. We cover project risk management and how to keep Android projects running smoothly.
Other audiences. This book is useful not only to the software developer, but also to the corporation looking at potential vertical market applications, the entrepreneur thinking about a cool phone application, and the hobbyist looking for some fun with his or her new phone. Businesses seeking to evaluate Android for their specific needs (including feasibility analysis) can also find the information provided valuable. Anyone with an Android handset and a good idea for a mobile application can put the information in this book to use for fun and profit.
Key Questions Answered in This Book
This book answers the following questions:
1. What is Android? How do the SDK versions differ?
2. How is Android different from other mobile technologies, and how can developers take advantage of these differences?
3. How do developers use the Android SDK and ADT Bundle to develop and debug Android applications on the emulator and handsets?
4. How are Android applications structured?
5. How do developers design robust user interfaces for mobile—specifically, for Android?
6. What capabilities does the Android SDK have and how can developers use them?
7. How does the mobile development process differ from traditional desktop development?
8. What strategies work best for Android development?
9. What do managers, developers, and testers need to look for when planning, developing, and testing a mobile application?
10. How do mobile teams design bulletproof Android applications for publication?
11. How do mobile teams package Android applications for deployment?
12. How do mobile teams make money from Android applications?
13. And, finally, what is new in this edition of the book?
How This Book Is Structured
Introduction to Android Application Development, Fourth Edition focuses on Android essentials, including setting up the development environment, understanding the application lifecycle, user interface design, developing for different types of devices, and the mobile software process from design and development to testing and publication of commercial-grade applications.
The book is divided into six parts. Here is an overview of the various parts:
Part I: An Overview of the Android Platform
Part I provides an introduction to Android, explaining how it differs from other mobile platforms. You become familiar with the Android SDK and tools, install the development tools, and write and run your first Android application—on the emulator and on a handset. This section is of primary interest to developers and testers, especially white-box testers.
Part II: Android Application Basics
Part II introduces the design principles necessary to write Android applications. You learn how Android applications are structured and how to include resources, such as strings, graphics, and user interface components, in your projects. This section is of primary interest to developers.
Part III: Android User Interface Design Essentials
Part III dives deeper into how user interfaces are designed in Android. You learn about the core user interface element in Android: the View. You also learn about the most common user interface controls and layouts provided in the Android SDK. This section is of primary interest to developers.
Part IV: Android Application Design Essentials
Part IV covers the features used by most Android applications, including storing persistent application data using preferences and working with files, directories, and content providers. You also learn how to design applications that will run smoothly on many different Android devices. This section is of primary interest to developers.
Part V: Publishing and Distributing Android Applications
Part V covers the software development process for mobile, from start to finish, with tips and tricks for project management, software developers, user experience designers, and quality assurance personnel.
Part VI: Appendixes
Part VI includes several helpful appendixes to help you get up and running with the most important Android tools. This section consists of an overview of the Android development tools, two helpful quick-start guides for the Android development tools—the emulator and DDMS—an appendix of Android IDE tips and tricks, as well as answers to the end-of-chapter quiz questions.
An Overview of Changes in This Edition
When we began writing the first edition of this book, there were no Android devices on the market. Today there are hundreds of devices shipping all over the world—smartphones, tablets, e-book readers, smart watches, and specialty devices such as gaming consoles, Google TV, and Google Glass. Other devices such as Google Chromecast provide screen sharing between Android devices and TVs.
The Android platform has gone through extensive changes since the first edition of this book was published. The Android SDK has many new features, and the development tools have received many much-needed upgrades. Android, as a technology, is now the leader within the mobile marketplace.
In this new edition, we took the opportunity to add a wealth of information about how to plan the Android application experience for users. In addition, we have included valuable and ready-to-use techniques for automating the testing of your Android applications, to ensure that you deliver high-quality code. We have also updated many chapters and accompanying content for making use of Fragment-based implementation approaches. But don’t worry, it’s still the book readers loved the first, second, and third time around; it’s just much bigger, better, and more comprehensive, following many best practices. In addition to adding new content, we’ve retested and upgraded all existing content (text and sample code) for use with the latest Android SDKs available while still remaining backward compatible. We created quiz questions to help readers ensure they understand each chapter’s content, and we added end-of-chapter exercises for readers to perform to dig deeper into all that Android has to offer. The Android development community is diverse, and we aim to support all developers, regardless of which devices they are developing for. This includes developers who need to target nearly all platforms, so coverage in some key areas of older SDKs continues to be included because it’s often the most reasonable option for compatibility.
Here are some of the highlights of the additions and enhancements we’ve made to this edition:
Coverage of the latest and greatest Android tools and utilities is included.
The topic of planning the Android application experience now has its own chapter, which includes a discussion of different navigation patterns with a new code sample and presents techniques that you can use to improve the quality of the user experience.
The chapter on testing has brand-new content to include topics such as unit testing and provides a practical code sample showing how to leverage the automated testing techniques used by the experts for testing their Android applications.
A new code sample and a discussion of how to add an ActionBar to your applications have been included.
The chapter on dialogs has been completely updated to make use of DialogFragments.
The chapter on Android preferences now includes an additional code sample with a brand-new discussion of how to add preference fragments that display accordingly within single-pane and multipane layouts.
The publishing chapter has been completely redesigned to discuss using the new Google Play Developer Console for publishing your applications, in addition to outlining new features provided within the console.
All chapters and appendixes now include quiz questions and exercises for readers to test their knowledge of the subject matter presented.
All existing chapters have been updated, often with some entirely new sections.
All sample code and accompanying applications have been updated to work with the latest SDK.
As you can see, we cover many of the hottest and most exciting features that Android has to offer. We didn’t take this review lightly; we touched every existing chapter, updated content, and added new chapters as well. Finally, we included many additions, clarifications, and, yes, even a few fixes based on the feedback from our fantastic (and meticulous) readers. Thank you!
Development Environments Used in This Book
The Android code in this book was written using the following development environments:
Android ADT Bundle (the adt-bundle-windows-x86-20130729.zip file was used)
Android SDK Version 4.3, API Level 18 (Jelly Bean)
Android SDK Tools Revision 22.0.5
Android SDK Platform Tools 18.0.1
Android SDK Build Tools 18.0.1
Android Support Library Revision 18 (where applicable)
Java SE Development Kit (JDK) 6 Update 45
Android devices: Nexus 4 (phone), Nexus 7 (small tablet), and Nexus 10 (large tablet)
The Android platform continues to grow aggressively in market share against competing mobile platforms, such as Apple iOS and BlackBerry. New and exciting types of Android devices reach consumers’ hands at a furious pace. Developers have embraced Android as a target platform to reach the device users of today and tomorrow.
Android’s latest major platform update, Android 4.3—frequently called by its code name, Jelly Bean, or just JB—brings many new features that help differentiate Android from the competition. This book features the latest SDK and tools available, but it does not focus on them to the detriment of popular legacy versions of the platform. The book is meant to be an overall reference to help developers support all popular devices on the market today. As of the writing of this book, approximately 37.9% of users’ devices are running a version of Android Jelly Bean, 4.1 or 4.2. Of course, some devices will receive upgrades, and users will purchase new Jelly Bean devices as they become available, but for now, developers need to straddle this gap and support numerous versions of Android to reach the majority of users in the field. In addition, the next version of the Android operating system is likely to be released in the near future.
So what does this mean for this book? It means we provide legacy API support and discuss some of the newer APIs available in later versions of the Android SDK. We discuss strategies for supporting all (or at least most) users in terms of compatibility. And we provide screenshots that highlight different versions of the Android SDK, because each major revision has brought with it a change in the look and feel of the overall platform. That said, we are assuming that you are downloading the latest Android tools, so we provide screenshots and steps that support the latest tools available at the time of writing, not legacy tools. Those are the boundaries we set when trying to determine what to include and leave out of this book.
Supplementary Materials Available
The source code that accompanies this book is available for download from our book’s website:
http://introductiontoandroid.blogspot.com/2013/05/book-code-samples.html. You’ll also find other Android topics discussed at our book website (http://introductiontoandroid.blogspot.com).
Where to Find More Information
There is a vibrant, helpful Android developer community on the Web. Here are a number of useful websites for Android developers and followers of the wireless industry:
Android Developer website: the Android SDK and developer reference site:
http://d.android.com/index.html or http://d.android.com
Google Plus: Android Developers Group
Stack Overflow: the Android website with great technical information (complete with tags) and an official support forum for developers:
Open Handset Alliance: Android manufacturers, operators, and developers:
Google Play: buy and sell Android applications:
Mobiletuts+: mobile development tutorials, including Android:
anddev.org: an Android developer forum:
Google Team Android Apps: open-source Android applications:
Android Tools Project Site: the tools team discusses updates and changes:
FierceDeveloper: a weekly newsletter for wireless developers:
Wireless Developer Network: daily news on the wireless industry:
XDA-Developers Android Forum: from general development to ROMs:
Developer.com: a developer-oriented site with mobile articles:
Conventions Used in This Book
This book uses the following conventions:
Code and programming terms are set in monospace text.
Java import statements, exception handling, and error checking are often removed from printed code examples for clarity and to keep the book a reasonable length.
This book also presents information in the following sidebars:
Tips provide useful information or hints related to the current text.
Notes provide additional information that might be interesting or relevant.
Warnings provide hints or tips about pitfalls that may be encountered and how to avoid them.