Beginning Android Application Development

( 1 )

Overview

Create must-have applications for the latest Android OS

The Android OS is a popular and flexible platform for many of today's most in-demand mobile devices. This full-color guide offers you a hands-on introduction to creating Android applications for the latest mobile devices. Veteran author Wei Meng Lee accompanies each lesson with real-world examples to drive home the content he covers. Beginning with an overview of core Android features and tools, he moves at a steady pace ...

See more details below
Paperback
$27.62
BN.com price
(Save 30%)$39.99 List Price

Pick Up In Store

Reserve and pick up in 60 minutes at your local store

Other sellers (Paperback)
  • All (22) from $2.64   
  • New (10) from $13.45   
  • Used (12) from $2.64   

Overview

Create must-have applications for the latest Android OS

The Android OS is a popular and flexible platform for many of today's most in-demand mobile devices. This full-color guide offers you a hands-on introduction to creating Android applications for the latest mobile devices. Veteran author Wei Meng Lee accompanies each lesson with real-world examples to drive home the content he covers. Beginning with an overview of core Android features and tools, he moves at a steady pace while teaching everything you need to know to successfully develop your own Android applications.

  • Explains what an activity is and reviews its lifecycle
  • Zeroes in on customizing activities by applying styles and themes
  • Looks at the components of a screen, including LinearLayout, AbsoluteLayout, and RelativeLayout, among others
  • Details ways to adapt to different screen sizes and adjust display orientation
  • Reviews the variety of views such as TextView, ProgressBar, TimePicker, and more

Beginning Android Application Development pares down the most essential steps you need to know so you can start creating Android applications today.

Read More Show Less

Product Details

  • ISBN-13: 9781118017111
  • Publisher: Wiley
  • Publication date: 4/19/2011
  • Edition number: 1
  • Pages: 448
  • Sales rank: 805,444
  • Product dimensions: 7.30 (w) x 9.10 (h) x 1.00 (d)

Meet the Author

Wei-Meng Lee is a technologist and founder of Developer Learning Solutions (www.learn2develop.net). He writes extensively for online publications and magazines on topics ranging from .NET to Mac OS X. In addition, he is the author of Beginning iOS 4 Application Development, as well as many other technology books and articles.

Read More Show Less

Table of Contents

INTRODUCTION xv

GETTING STARTED W CHAPTER 1: ITH ANDROID PROGRAMMING 1

CHAPTER 2: ACTIVITIES AND INTENTS 27

CHAPTER 3: GETTING TO KNOW THE ANDROID USER INTERFACE 81

CHAPTER 4: DESIGNING YOUR USER INTERFACE USING VIEWS 125

CHAPTER 5: DISPLAYING PICTURES AND MENUS WITH VIEWS 169

CHAPTER 6: DATA PERSISTENCE 203

CHAPTER 7: CONTENT PROVIDERS 237

CHAPTER 8: MESSAGING AND NETWORKING 263

CHAPTER 9: LOCATION-BASED SERVICES 301

CHAPTER 10: DEVELOPING ANDROID SERVICES 331

CHAPTER 11: PUBLISHING ANDROID APPLICATIONS 359

APPENDIX A: USING ECLIPSE FOR ANDROID DEVELOPMENT 381

APPENDIX B: USING THE ANDROID EMULATOR 393

APPENDIX C: ANSWERS TO EXERCISES 411

INDEX 415

Read More Show Less

First Chapter

Beginning Android Application Development


By Wei-Meng Lee

John Wiley & Sons

Copyright © 2011 John Wiley & Sons, Ltd
All right reserved.

ISBN: 978-1-1180-1711-1


Chapter One

Getting Started with Android Programming

WHAT YOU WILL LEARN IN THIS CHAPTER

* What is Android?

* Android versions and its feature set

* The Android architecture

* The various Android devices on the market

* The Android Market application store

* How to obtain the tools and SDK for developing Android applications

* How to develop your first Android application

Welcome! The fact that you are holding this book in your hands (or are reading it on your latest mobile device) signifies that you are interested in learning how to write applications for the Android platform — and there's no better time to do this than now! The mobile application market is exploding, and recent market research shows that Android has overtaken iPhone to occupy the second position in the U.S. smartphone market. The first place honor currently goes to Research In Motion (RIM), with Apple's iPhone taking third place. By the time you read this, chances are good that Android may have become the number one smartphone platform in the U.S., and that you may even be reading this on one of the latest Android devices.

What propelled this relatively unknown operating system, which Google bought in 2005, to its popular status today? And what features does it offer? In this chapter you will learn what Android is, and what makes it so compelling to both developers and device manufacturers alike. You will also get started with developing your first Android application, and learn how to obtain all the necessary tools and set them up. By the end of this chapter, you will be equipped with the basic knowledge you need to explore more sophisticated techniques and tricks for developing your next killer Android application.

WHAT IS ANDROID?

Android is a mobile operating system that is based on a modified version of Linux. It was originally developed by a startup of the same name, Android, Inc. In 2005, as part of its strategy to enter the mobile space, Google purchased Android and took over its development work (as well as its development team).

Google wanted Android to be open and free; hence, most of the Android code was released under the open-source Apache License, which means that anyone who wants to use Android can do so by downloading the full Android source code. Moreover, vendors (typically hardware manufacturers) can add their own proprietary extensions to Android and customize Android to differentiate their products from others. This simple development model makes Android very attractive and has thus piqued the interest of many vendors. This has been especially true for companies affected by the phenomenon of Apple's iPhone, a hugely successful product that revolutionized the smartphone industry. Such companies include Motorola and Sony Ericsson, which for many years have been developing their own mobile operating systems. When the iPhone was launched, many of these manufacturers had to scramble to find new ways of revitalizing their products. These manufacturers see Android as a solution — they will continue to design their own hardware and use Android as the operating system that powers it.

The main advantage of adopting Android is that it offers a unified approach to application development. Developers need only develop for Android, and their applications should be able to run on numerous different devices, as long as the devices are powered using Android. In the world of smartphones, applications are the most important part of the success chain. Device manufacturers therefore see Android as their best hope to challenge the onslaught of the iPhone, which already commands a large base of applications.

Android Versions

Android has gone through quite a number of updates since its first release. Table 1-1 shows the various versions of Android and their codenames.

Features of Android

As Android is open source and freely available to manufacturers for customization, there are no fixed hardware and software configurations. However, Android itself supports the following features:

* Storage — Uses SQLite, a lightweight relational database, for data storage. Chapter 6 discusses data storage in more detail.

* Connectivity — Supports GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth (includes A2DP and AVRCP), WiFi, LTE, and WiMAX. Chapter 8 discusses networking in more detail.

* Messaging — Supports both SMS and MMS. Chapter 8 discusses messaging in more detail.

* Web browser — Based on the open-source WebKit, together with Chrome's V8 JavaScript engine

* Media support — Includes support for the following media: H.263, H.264 (in 3GP or MP4 container), MPEG-4 SP, AMR, AMR-WB (in 3GP container), AAC, HE-AAC (in MP4 or 3GP container), MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP

* Hardware support — Accelerometer Sensor, Camera, Digital Compass, Proximity Sensor, and GPS

* Multi-touch — Supports multi-touch screens

* Multi-tasking — Supports multi-tasking applications

* Flash support — Android 2.3 supports Flash 10.1.

* Tethering — Supports sharing of Internet connections as a wired/wireless hotspot

Architecture of Android

In order to understand how Android works, take a look at Figure 1-1, which shows the various layers that make up the Android operating system (OS).

The Android OS is roughly divided into five sections in four main layers:

* Linux kernel — This is the kernel on which Android is based. This layer contains all the lowlevel device drivers for the various hardware components of an Android device.

* Libraries — These contain all the code that provides the main features of an Android OS. For example, the SQLite library provides database support so that an application can use it for data storage. The WebKit library provides functionalities for web browsing.

* Android runtime — At the same layer as the libraries, the Android runtime provides a set of core libraries that enable developers to write Android apps using the Java programming language. The Android runtime also includes the Dalvik virtual machine, which enables every Android application to run in its own process, with its own instance of the Dalvik virtual machine (Android applications are compiled into the Dalvik executables). Dalvik is a specialized virtual machine designed specifically for Android and optimized for battery-powered mobile devices with limited memory and CPU.

* Application framework — Exposes the various capabilities of the Android OS to application developers so that they can make use of them in their applications.

* Applications — At this top layer, you will find applications that ship with the Android device (such as Phone, Contacts, Browser, etc.), as well as applications that you download and install from the Android Market. Any applications that you write are located at this layer.

Android Devices in the Market

Android devices come in all shapes and sizes. As of late November 2010, the Android OS can be seen powering the following types of devices:

* Smartphones

* Tablets

* E-reader devices

* Netbooks

* MP4 players

* Internet TVs

Chances are good that you own at least one of the preceding devices. Figure 1-2 shows (clockwise) the Samsung Galaxy S, the HTC Desire HD, and the LG Optimus One smartphones.

Another popular category of devices that manufacturers are rushing out is the tablet. Tablet sizes typically start at seven inches, measured diagonally. Figure 1-3 shows the Samsung Galaxy Tab and the Dell Streak, which is a five-inch phone tablet.

Besides smartphones and tablets, Android is also beginning to appear in dedicated devices, such as e-book readers. Figure 1-4 shows the Barnes and Noble's NOOKcolor, which is a color e-Book reader running the Android OS.

In addition to these popular mobile devices, Android is also slowly finding its way into your living room. People of Lava, a Swedish company, has developed an Android-based TV, call the Scandinavia Android TV (see Figure 1-5).

Google has also ventured into a proprietary smart TV platform based on Android and co-developed with companies such as Intel, Sony, and Logitech. Figure 1-6 shows Sony's Google TV.

The Android Market

As mentioned earlier, one of the main factors determining the success of a smartphone platform is the applications that support it. It is clear from the success of the iPhone that applications play a very vital role in determining whether a new platform swims or sinks. In addition, making these applications accessible to the general user is extremely important.

As such, in August 2008, Google announced the Android Market, an online application store for Android devices, and made it available to users in October 2008. Using the Market application that is preinstalled on their Android device, users can simply download third-party applications directly onto their devices. Both paid and free applications are supported on the Android Market, though paid applications are available only to users in certain countries due to legal issues.

Similarly, in some countries, users can buy paid applications from the Android Market, but developers cannot sell in that country. As an example, at the time of writing, users in India can buy apps from the Android Market, but developers in India cannot sell apps on the Android Market. The reverse may also be true; for example, users in South Korea cannot buy apps, but developers in South Korea can sell apps on the Android Market.

Chapter 11 discusses more about the Android Market and how you can sell your own applications in it.

OBTAINING THE REQUIRED TOOLS

Now that you know what Android is and its feature set, you are probably anxious to get your hands dirty and start writing some applications! Before you write your first app, however, you need to download the required tools and SDKs.

For Android development, you can use a Mac, a Windows PC, or a Linux machine. All the tools needed are free and can be downloaded from the Web. Most of the examples provided in this book should work fine with the Android emulator, with the exception of a few examples that require access to the hardware. For this book, I will be using a Windows 7 computer to demonstrate all the code samples. If you are using a Mac or Linux computer, the screenshots should look similar; some minor differences may be present, but you should be able to follow along without problems.

So, let the fun begin!

Eclipse

The first step towards developing any applications is obtaining the integrated development environment (IDE). In the case of Android, the recommended IDE is Eclipse, a multi-language software development environment featuring an extensible plug-in system. It can be used to develop various types of applications, using languages such as Java, Ada, C, C++, COBOL, Python, etc.

For Android development, you should download the Eclipse IDE for Java EE Developers (www.eclipse.org/downloads/packages/eclipse-ide-java-eedevelopers/heliossr1). Six editions are available: Windows (32 and 64-bit), Mac OS X (Cocoa 32 and 64), and Linux (32 and 64-bit). Simply select the relevant one for your operating system. All the examples in this book were tested using the 32-bit version of Eclipse for Windows.

Once the Eclipse IDE is downloaded, unzip its content (the eclipse folder) into a folder, say C:\Android\. Figure 1-7 shows the content of the eclipse folder.

Android SDK

The next important piece of software you need to download is, of course, the Android SDK. The Android SDK contains a debugger, libraries, an emulator, documentation, sample code, and tutorials.

You can download the Android SDK from http://developer.android.com/sdk/ index.html.

Once the SDK is downloaded, unzip its content (the android-sdk-windows folder) into the C:\Android\ folder, or whatever name you have given to the folder you just created.

Android Development Tools (ADT)

The Android Development Tools (ADT) plug-in for Eclipse is an extension to the Eclipse IDE that supports the creation and debugging of Android applications. Using the ADT, you will be able to do the following in Eclipse:

* Create new Android application projects.

* Access the tools for accessing your Android emulators and devices.

* Compile and debug Android applications.

* Export Android applications into Android Packages (APK).

* Create digital certificates for code-signing your APK.

To install the ADT, first launch Eclipse by double-clicking on the eclipse.exe file located in the eclipse folder.

When Eclipse is first started, you will be prompted for a folder to use as your workspace. In Eclipse, a workspace is a folder where you store all your projects. Take the default suggested and click OK.

Once Eclipse is up and running, select the Help -> Install New Software ... menu item (see Figure 1-8).

In the Install window that appears, type http://dl-ssl.google.com/android/eclipse in the text box (see Figure 1-9) and click Add....

After a while, you will see the Developer Tools item appear in the middle of the window (see Figure 1-10). Expand it, and it will reveal its content: Android DDMS, Android Development Tools, and Android Hierarchy Viewer. Check all of them and click Next.

When you see the installation details, as shown in Figure 1-11, click Next.

You will be asked to review the licenses for the tools. Check the option to accept the license agreements (see Figure 1-12). Click Finish to continue.

Eclipse will now proceed to download the tools from the Internet and install them (see Figure 1-13). This will take some time, so be patient.

Once the ADT is installed, you will be prompted to restart Eclipse. After doing so, go to Window Preferences (see Figure 1-14).

In the Preferences window that appears, select Android. You will see an error message saying that the SDK has not been set up (see Figure 1-15). Click OK to dismiss it.

Enter the location of the Android SDK folder. In this example, it would be C:\Android\ android-sdk-windows. Click OK.

Creating Android Virtual Devices (AVDs)

The next step is to create AVD to be used for testing your Android applications. AVD stands for Android Virtual Devices. An AVD is an emulator instance that enables you to model an actual device.

Each AVD consists of a hardware profile, a mapping to a system image, as well as emulated storage, such as a secure digital (SD) card.

You can create as many AVDs as you want in order to test your applications with several different configurations. This testing is important to confirm the behavior of your application when it is run on different devices with varying capabilities.

NOTE Appendix B will discuss some of the capabilities of the Android Emulator.

To create an AVD, go to Windows Android SDK and AVD Manager.

Select the Available packages option in the left pane and expand the package name shown in the right pane. Figure 1-16 shows the various packages available for you to create AVDs to emulate the different versions of an Android device.

Check the relevant tools, documentation, and platforms you need for your project.

Once you have selected the items you want, click the Install Selected button to download them. Because it takes a while to download from Google's server, it is a good idea to download only whatever you need immediately, and download the rest when you have more time.

NOTE For a start, you should at least select the latest SDK platform. At the time of writing, the latest SDK platform is SDK Platform Android 2.3, API 9, revision 1.

Each version of the Android OS is identified by an API level number. For example, Android 2.3 is level 9 (API 9), while Android 2.2 is level 8 (API 8), and so on. For each level, two platforms are available. For example, level 9 offers the following:

* SDK Platform Android 2.3

* Google APIs by Google Inc.

The key difference between the two is that the Google APIs platform contains the Google Maps library. Therefore, if the application you are writing requires Google Maps, you need to create an AVD using the Google APIs platform (more on this in Chapter 9, "Location Based Services."

Click the Virtual Devices item in the left pane of the window. Then click the New ... button located in the right pane of the window.

In the Create new Android Virtual Device (AVD) window, enter the items as shown in Figure 1-17. Click the Create AVD button when you are done.

In this case, you have created an AVD (put simply, an Android emulator) that emulates an Android device running version 2.3 of the OS. In addition to what you have created, you also have the option to emulate the device with an SD card and different screen densities and resolutions.

(Continues...)



Excerpted from Beginning Android Application Development by Wei-Meng Lee Copyright © 2011 by John Wiley & Sons, Ltd. Excerpted by permission of John Wiley & Sons. All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Read More Show Less

Customer Reviews

Average Rating 3
( 1 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(1)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Posted April 21, 2011

    Not for beginners. Vast amounts of code.

    Some programming books push concepts, some push code. This book is a code pusher. Short explanations followed by large amounts of code. This does NOT making learning easy. It makes finding android assignments easy. Learn the concepts elsewhere and use this book to practice your craft. If you are a true android beginner you will be lost. I would give the book a much higher rating had it been given a more accurate title like "android application recipes for beginners." Seriously, pick a random page and flip to it and you'll see a wall of bolded code to type up. Having said the above: I actually look forward to coding everything this book has to offer. I've learned the concepts from other actual beginner texts which has prepared me for this book. Had I not prepared myself, this text would have been returned. End of chapters have great lists of important lines of code and what they do. So basically, this book is a great reference tool & great for coding tutorials when you want some practice. I mean, if you can learn from large amounts of code you probably don't need a book anyway, right? It is NOT for the newbie at all.

    4 out of 5 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)