Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

About this Book

About this Book

Android in Action, Third Edition is a revision and update of, you guessed it, the Second Edition, published in January 2011. This third edition adds new content related to Android’s push into the tablet space as well as enhancements to various sub-systems within the Android platform. Like its predecessors, this book covers important beginner topics such as “What is Android?” and installing and using the development environment. We then advance to practical working examples of core programming topics any developer will be happy to have at the ready on the reference shelf. The remaining chapters present detailed example applications covering advanced topics, including a complete field-service application, localization, and material on Android web applications, Bluetooth, sensors, AppWidgets, and integration adapters. We even include two chapters on writing applications in C—one for the native side of Android and one using the more generally accepted method of employing the Android Native Development Kit. Brand-new content covering tablet programming is found in chapters 20 through 22. Chapters 2022 specifically require Android SDK 3.0 and beyond, whereas the balance of the book is compatible with 2.x versions of Android.

Although you can read the book from start to finish, you can also consider it a few books in one. If you’re new to Android, focus first on chapter 1, appendix A, and then chapter 2. With that foundation, you can work your way through chapters 312. Chapters 13 and on are more in-depth in nature and can be read independently of the others. Chapters 2022 focuses on important topics related to Android 3.0 and tablets.

Who should read this book?

We wrote this book for professional programmers and hobbyists alike. Many of the concepts can be absorbed without specific Java language knowledge, although you’ll obtain the most value if you have Java programming skills—Android application programming requires them. If you have C, C++, or C# programming knowledge, you’ll be able to follow the examples.

Prior Eclipse experience is helpful, but not required. A number of good resources are available on Java and Eclipse to augment the content of this book.

Roadmap

This book is divided into four parts. Part 1 contains introductory material about the platform and development environment. Part 2 takes a close look at the fundamental skills required for building Android applications. Part 3 presents a larger-scope application and a Native C Android application. Part 4 explores features added to the Android platform, providing examples of using the capable Android platform to create innovative mobile applications.

Part 1: The essentials

Part 1 introduces the Android platform, including its architecture and setting up the development environment.

Chapter 1 delves into the background and positioning of the Android platform, including comparisons to other popular platforms such as BlackBerry, iPhone, and Windows Mobile. After an introduction to the platform, the balance of the first chapter introduces the high-level architecture of Android applications and the operating system environment.

Chapter 2 takes you on a step-by-step development exercise, teaching you the ropes of using the Android development environment, including the key tools and concepts for building an application. If you’ve never used Eclipse or have never written an Android application, this chapter will prepare you for the next part of the book.

Part 2: The programming environment

Part 2 includes an extensive survey of fundamental programming topics in the Android environment.

Chapter 3 covers the fundamental Android UI components, including View and Layout. We also review the Activity in more detail. These are the basic building blocks of screens and applications on the Android platform. Along the way, we also touch on other basic concepts such as accessing external resources, responding to events, and the lifecycle of an Android application.

Chapter 4 expands on the concepts you learned in chapter 3. We delve into the Android Intent to demonstrate interaction between screens, activities, and entire applications. We also introduce and use the Service framework, which allows for ongoing background processes.

Chapter 5 incorporates methods and strategies for storing and retrieving data locally. The chapter examines use of the filesystem, databases, the SD card, and Android-specific storage entities such as the SharedPreferences and ContentProvider classes. This chapter begins combining fundamental concepts with more real-world details, such as handling application state, using a database for persistent storage, and working with SQLite.

Chapter 6 deals with storing and retrieving data over the network. Here we include a networking primer before delving into using raw networking concepts such as sockets on Android. From there, we progress to using HTTP, and even explore web services (such as REST and SOAP).

Chapter 7 covers telephony on the Android platform. We touch on basics such as originating and receiving phone calls, as well as more involved topics such as identifying cell towers and sending or receiving SMS messages.

Chapter 8 looks at how to work with notifications and alarms. In this chapter, we look at how to notify users of various events such as receiving a SMS message, as well as how to manage and set alarms.

Chapter 9 deals with the basics of Android’s Graphics API and more advanced concepts such as working with the OpenGL ES library for creating sophisticated 2D and 3D graphics. We also touch on animation as well as Android’s new graphics systems RenderScript.

Chapter 10 looks at Android’s support for multimedia; we cover both playing multimedia as well as using the camera and microphone to record your own multimedia files.

Chapter 11 introduces location-based services as we look at an example that combines many of the concepts from the earlier parts of the book in a mapping application. You’ll learn about using the mapping APIs on Android, including different location providers and properties that are available, how to build and manipulate map-related screens, and how to work with location-related concepts within the emulator.

Part 3: Bringing it all together

Part 3 contains two chapters, both of which build on knowledge you gained earlier in the text, with a focus on bringing a larger application to fruition.

Chapter 12 demonstrates an end-to-end field service application. The application includes server communications, persistent storage, multiple Activity navigation menus, and signature capture.

Chapter 13 explores the world of native C language applications. The Android SDK is limited to the Java language, although native applications can be written for Android. This chapter walks you through examples of building C language applications for Android, including the use of built-in libraries and TCP socket communications as a Java application connects to your C application. This chapter is useful for developers targeting solutions beyond carrier-subsidized, locked-down cell phones.

Part 4: The maturing platform

Part 4 contains nine new chapters, each of which represents a more advanced development topic.

Chapter 14 demonstrates the use of both Bluetooth communication and processing sensor data. The sample application accompanying the chapter, SenseBot, permits the user to drive a LEGO Mindstorms robot with their Android phone.

Chapter 15 explores the Android contact database and demonstrates integrating with an external data source. In particular, this application brings Android into the social-networking scene by integrating with the popular LinkedIn professional networking service.

Chapter 16 explores the world of web development. Android’s browser is based on the open source WebKit engine and brings desktop-like capability to this mobile browser. This chapter equips you to bring attractive and capable web applications to Android.

Chapter 17 brings the home screen of your Android application to life by showing you how to build an application that presents its user interface as an AppWidget. In addition to AppWidgets, this chapter demonstrates BroadcastReceiver, Service, and Alarms.

Chapter 18 takes a real-world look at localizing an existing application. Chapter 12’s Field Service application is modified to support multiple languages. Chapter 18’s version of the Field Service application contains support for both English and Spanish.

Chapter 19 reaches into Android’s open source foundation by using a popular edge-detection image-processing algorithm. The Sobel Edge Detection algorithm is written in C and compiled into a native library. The sample application snaps a picture with the Android camera and then uses this C algorithm to find the edges in the photo.

Chapter 20 covers Android Fragments, a new application component that was introduced with Android 3.0. Fragments provide more granular application control than working only with Activitys alone.

Chapter 21 explores the action bar. Also introduced with Android 3.0, the action bar provides a consistent look-and-feel for the application title, icon, actions, and menu options.

Chapter 22 introduces the new drag-and-drop API, also introduced with Android 3.0. The drag-and-drop API allows for touch-based, interactive operations: for example, to move or copy data across views by visually selecting data from one view and dropping it onto another view on the screen. Another example is to trigger application actions: for example, image sharing by dragging an image from an image gallery view onto a sharing view.

Appendixes

The appendixes contain additional information that didn’t fit with the flow of the main text. Appendix A is a step-by-step guide to installing the development environment. This appendix, along with chapter 2, provides all the information you need to build an Android application. Appendix B demonstrates how to prepare and submit an application for the Android Market—an important topic for anyone looking to sell an application commercially.

Code conventions and downloads

All source code in the book is in a fixed-width font like this, which sets it off from the surrounding text. In many listings, the code is annotated to point out the key concepts, and numbered bullets are sometimes used in the text to provide additional information about the code. We have tried to format the code so that it fits within the available page space in the book by adding line breaks and using indentation carefully. Sometimes, however, very long lines include line-continuation markers.

Source code for all the working examples is available from www.manning.com/AndroidinActionThirdEdition or www.manning.com/ableson3. A Readme.txt file is provided in the root folder and also in each chapter folder; the files provide details on how to install and run the code. Code examples appear throughout this book. Longer listings appear under clear listing headers, whereas shorter listings appear between lines of text.

Software requirements

Developing applications for Android may be done from the Windows XP/Vista/7 environment, a Mac OS X (Intel only) environment, or a Linux environment. Appendix A includes a detailed description of setting up the Eclipse environment along with the Android Developer Tools plug-in for Eclipse.

A note about the graphics

Many of the original graphics from the first edition, Unlocking Android, have been reused in the second and third editions of the book. Although the title was changed to Android in Action during the writing of the second edition, we kept the original book title in our graphics and sample applications.

Author Online

Purchase of Android in Action, Third Edition 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 www.manning.com/AndroidinActionThirdEdition or www.manning.com/ableson3. This page provides information on how to get on the forum once you’re 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 dialog between individual readers and between readers and the authors can take place. It’s not a commitment to any specific amount of participation on the part of the authors, whose contribution to the AO 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.

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint