About this Book

Android is an open source mobile device platform created by Google and the Open Handset Alliance. Android powers smartphones, tablets, set-top boxes, TVs, and more. Android in Practice is a book dedicated to helping developers build applications for the Android platform.

This book is intended to provide some background information and coverage of the basics of developing applications for Android for beginners and also goes into depth on many topics for intermediate to advanced developers. The overall goal of Android in Practice is to collect and organize helpful Android programming techniques over a variety of topics and explain those techniques in the context of the overall platform. We’re going for the why as much as the how. You will find 91 techniques in the book, each consisting of a problem, solution, and discussion section.

Who should read this book?

This is a book about developing applications for the Android platform, from key components and application basics to advanced techniques, testing, building, project management, and more. We hope this book will appeal to Android developers of varying skill levels, from beginner to advanced; Android testers; and managers and team leaders looking to better understand Android development.

This book is intended for people who already have some programming experience and are at least familiar with Java. Therefore, we assume that most readers are somewhat familiar with Java and related technologies (working with IDEs, compiling and writing Java code, XML, basic networking, and so forth).

Roadmap

Chapter 1 introduces Android, the platform and talks about the progression that led to it, the companies behind it, and what sets it apart. It also introduces the core Android APIs and tools and includes a “hello world” programming example.

Chapter 2 covers all of the key components needed in a basic Android application, including resources, layout, views, activities, adapters, and intents.

Chapter 3 discusses the details of the lifecycle of an Android application and of activities. We discuss both the stack of activities an application includes and how activities are grouped into tasks.

Chapter 4 focuses entirely on the user interface. This includes how views are created and rendered, how they’re arranged in layouts, how adapters are used to manage them, how they can be styled and reused, working with drawables, and handling devices with different screen sizes.

Chapter 5 provides details on multitasking using services. This goes from what a service is and why it’s necessary to how they can be created, how they can be started automatically or scheduled with alarms, how they can be used to cache data and send notifications, and how to push messages from the cloud to devices.

Chapter 6 details where threads and asynchronous tasks can be used to make Android applications more responsive and performant. The topics covered include communicating between threads, managing threads, using handlers and timers, message loops, and more.

Chapter 7 deals with working with external and internal storage to store data. This includes using the filesystem and preferences files and working with SQLite and databases.

Chapter 8 deals with sharing data between different applications. This includes consuming data from other applications on the platform and providing data to other applications, both using a content provider.

Chapter 9 extends the concepts of storing and sharing data by using the network. This means using HTTP from several different clients, working with web services using XML and JSON, understanding how to detect and switch between different network data sources, and recovering gracefully from networking problems.

Chapter 10 deals with location-related services. This includes determining what location providers are present and what resources each requires, obtaining location data from different sources, and building map-based applications.

Chapter 11 features multimedia. The topics here include detecting multimedia capabilities, working with resources and files, using media related content providers, and working with audio and video, including using the camera, displaying animations, and controlling audio playback.

Chapter 12 delves into 2D and 3D drawing. This is where we learn about drawing shapes and lines on the canvas, creating effects, building custom views, and working with 3D programming using OpenGL ES.

Chapter 13 covers automated testing of Android applications. This includes working with different types of tests and several different test approaches and frameworks.

Chapter 14 discusses project management and build automation. This includes an overview of all the steps required in an Android build, coverage of working with build tools such as Ant and Maven, and continuous integration of Android builds with Hudson.

Chapter 15 targets developing for Android tablets. This includes using existing code libraries, targeting different devices, working with activity fragments, and different user interface components for tablets.

Appendix A picks up several questions involving debugging Android applications and gives some useful advice on how to effectively use the Android Debug Bridge. It also covers a recent addition to Android called StrictMode, which allows you to detect performance smells in your applications.

Appendix B presents Android application development from an entirely new perspective, as it explores two alternative approaches to native Android development: using WebViews and programming in alternative languages like Scala.

Appendix C covers use of the ProGuard byte code optimizer and obfuscator, something you should have on your radar for any production-quality application.

Appendix D covers monkeyrunner, a scripted tool used to instrument Android applications. This is our attempt to shed some light on a useful but underdocumented tool.

Code conventions and downloads

This book contains many example projects, all of which are based on multiple code listings. We’ve tried to be as thorough as possible in the listings and yet keep them concise, but this isn’t always easy with Java and XML. Many of the listings also include code annotations that highlight important concepts and explain portions. These annotations are discussed in the text.

In some listings we’ve omitted the more verbose or boilerplate portions of the code where we feel it makes sense to do so. For example, after we’ve introduced one concept, we typically don’t keep repeating the same technique in the code listings. We know it can be frustrating to not have complete examples, but it’s also impossible to include all of the code this book covers in its entirety and still adequately discuss the related concepts. We’ve tried to strike a balance and indicate in the listings wherever code is omitted for brevity, and we’ve also included every line of code as a complete working project available for download as either source or in working binary form at the Android in Practice Google Code hosting site: http://code.google.com/p/android-in-practice/. The code is also available from the publisher’s website at http://www.manning.com/AndroidinPractice.

Author Online

The purchase of Android in Practice includes free access to a private web forum run by Manning Publications, where you can make comments about the book, ask technical questions, and receive help from the authors and from other users. To access the forum and subscribe to it, point your web browser to http://manning.com/AndroidinPractice. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the authors can take place. It isn’t a commitment to any specific amount of participation on the part of the authors, whose contribution to the forum remains voluntary (and unpaid). We suggest you try asking the authors some challenging questions lest their interest stray!

The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

About the authors

CHARLIE COLLINS is the director of development at MOVL, where he helps create apps that allow connected TVs and mobile devices to interact. Charlie has worked on several open source projects and has a strong background in web applications and web services. Charlie was also the coauthor of Manning’s GWT in Practice and Unlocking Android. When he’s not coding Android apps or writing server logic, Charlie can often be found playing tennis or mountain biking. Charlie lives in Atlanta, Georgia, with his wife and two daughters.

MICHAEL GALPIN is a developer at Bump Technologies where he works on Bump, one of the most popular social networking apps on the Android Market. Prior to that, he was at eBay for four years where he worked on eBay Mobile for Android, one of the most popular shopping apps. He frequently writes articles about open source technology for IBM developerWorks. He lives in San Jose, California, with his wife and two sons.

MATTHIAS KÄPPLER is a developer at Qype.com, Europe’s largest community portal for local reviews, where he leads development in Qype’s mobile products division, the “A-Team” (Android and API). He has been all over Android from its early alpha day and has founded or contributed to several well-received open source projects, including Signpost OAuth, Droid-Fu, Calculon, and Gradle’s Android plugin. In his spare time he’s a music, movie, and coffee addict, and when not busy discovering new locations and reviewing them on Qype, he’s probably practicing Taekkyon, a Korean martial art. Matthias lives in Hamburg, Germany.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.102.112