Académique Documents
Professionnel Documents
Culture Documents
Summary: Android is a complete operating environment based upon the Linux® V2.6 kernel. Initially, the
deployment target for Android was the mobile-phone arena, including smart phones and lower-cost flip-phone
devices. However, Android's full range of computing services and rich functional support have the potential to
extend beyond the mobile-phone market. Android can be useful for other platforms and applications. In this
article, get an introduction to the Android platform and learn how to code a basic Android application.
Introduction
The BlackBerry and iPhone, which have appealing and high-volume mobile platforms, are addressing opposite
ends of a spectrum. The BlackBerry is rock-solid for the enterprise business user. For a consumer device, it's
hard to compete with the iPhone for ease of use and the "cool factor." Android, a young and yet-unproven
platform, has the potential to play at both ends of the mobile-phone spectrum and perhaps even bridge the gulf
between work and play.
Today, many network-based or network-capable appliances run a flavor of the Linux kernel. It's a solid platform:
cost-effective to deploy and support and readily accepted as a good design approach for deployment. The UI for
such devices is often HTML-based and viewable with a PC or Mac browser. But not every appliance needs to be
controlled by a general computing device. Consider a conventional appliance, such as a stove, microwave or
bread maker. What if your household appliances were controlled by Android and boasted a color touch screen?
With an Android UI on the stove-top, the author might even be able to cook something.
In this article, learn about the Android platform and how it can be used for mobile and nonmobile applications.
Install the Android SDK and build a simple application. Download the source code for the example application
in this article.
The Android platform is the product of the Open Handset Alliance, a group of organizations collaborating to
build a better mobile phone. The group, led by Google, includes mobile operators, device handset
manufacturers, component manufacturers, software solution and platform providers, and marketing companies.
From a software development standpoint, Android sits smack in the middle of the open source world.
The first Android-capable handset on the market was the G1 device manufactured by HTC and provisioned on
T-Mobile. The device became available after almost a year of speculation, where the only software development
tools available were some incrementally improving SDK releases. As the G1 release date neared, the Android
team released SDK V1.0 and applications began surfacing for the new platform.
To spur innovation, Google sponsored two rounds of "Android Developer Challenges," where millions of dollars
were given to top contest submissions. A few months after the G1, the Android Market was released, allowing
users to browse and download applications directly to their phones. Over about 18 months, a new mobile
With Android's breadth of capabilities, it would be easy to confuse it with a desktop operating system. Android
is a layered environment built upon a foundation of the Linux kernel, and it includes rich functions. The UI
subsystem includes:
Windows
Views
Widgets for displaying common elements such as edit boxes, lists, and drop-down lists
Android includes an embeddable browser built upon WebKit, the same open source browser engine powering
the iPhone's Mobile Safari browser.
Android boasts a healthy array of connectivity options, including WiFi, Bluetooth, and wireless data over a
cellular connection (for example, GPRS, EDGE, and 3G). A popular technique in Android applications is to link
to Google Maps to display an address directly within an application. Support for location-based services (such
as GPS) and accelerometers is also available in the Android software stack, though not all Android devices are
equipped with the required hardware. There is also camera support.
Historically, two areas where mobile applications have struggled to keep pace with their desktop counterparts
are graphics/media, and data storage methods. Android addresses the graphics challenge with built-in support
for 2-D and 3-D graphics, including the OpenGL library. The data-storage burden is eased because the Android
platform includes the popular open source SQLite database. Figure 1 shows a simplified view of the Android
software layers.
Application architecture
As mentioned, Android runs atop a Linux kernel. Android applications are written in the Java programming
language, and they run within a virtual machine (VM). It's important to note that the VM is not a JVM as you
might expect, but is the Dalvik Virtual Machine, an open source technology. Each Android application runs
within an instance of the Dalvik VM, which in turn resides within a Linux-kernel managed process, as shown
below.
Figure 2. Dalvik VM
Activities
An application that has a visible UI is implemented with an activity. When a user selects an application
from the home screen or application launcher, an activity is started.
Services
A service should be used for any application that needs to persist for a long time, such as a network
monitor or update-checking application.
Content providers
You can think of content providers as a database server. A content provider's job is to manage access to
persisted data, such as a SQLite database. If your application is very simple, you might not necessarily
create a content provider. If you're building a larger application, or one that makes data available to
multiple activities or applications, a content provider is the means of accessing your data.
Broadcast receivers
An Android application may be launched to process a element of data or respond to an event, such as the
receipt of a text message.
The next section discusses the development environment required to build an Android application.
Required tools
The easiest way to start developing Android applications is to download the Android SDK and the Eclipse IDE
(see Resources). Android development can take place on Microsoft® Windows®, Mac OS X, or Linux.
This article assumes you are using the Eclipse IDE and the Android Developer Tools plug-in for Eclipse.
Android applications are written in the Java language, but compiled and executed in the Dalvik VM (a non-Java
virtual machine). Coding in the Java language within Eclipse is very intuitive; Eclipse provides a rich Java
environment, including context-sensitive help and code suggestion hints. Once your Java code is compiled
cleanly, the Android Developer Tools make sure the application is packaged properly, including the
AndroidManifest.xml file.
It's possible to develop Android applications without Eclipse and the Android Developer Tools plug-in, but you
would need to know your way around the Android SDK.
The Android SDK is distributed as a ZIP file that unpacks to a directory on your hard drive. Since there have
been several SDK updates, it is recommended that you keep your development environment well organized so
you can easily switch between SDK installations. The SDK includes:
android.jar
Java archive file containing all of the Android SDK classes necessary to build your application.
Android applications may be run on a real device or on the Android Emulator, which ships with the Android
SDK. Figure 3 shows the Android Emulator's home screen.
The adb utility supports several optional command-line arguments that provide powerful features, such as
copying files to and from the device. The shell command-line argument lets you connect to the phone itself and
issue rudimentary shell commands. Figure 4 shows the adb shell command against a real device connected to a
Windows laptop with a USB cable.
Display the network configuration that shows multiple network connections. Note the multiple network
connections:
lo is the local or loopback connection.
tiwlan0 is the WiFi connection with an address provisioned by a local DHCP server.
Display the contents of the PATH environment variable.
Execute the su command to become the super-user.
Change the directory to /data/app, where user applications are stored.
Do a directory listing where you see a single application. Android application files are actually archive files
that are viewable with WinZip or equivalent. The extension is apk.
Issue a ping command to see if Google.com is available.
From this same command-prompt environment, you can also interact with SQLite databases, start programs,
and many other system-level tasks. This is fairly remarkable function, considering you're connected to a
telephone.
This section provides a whirlwind tour of building an Android application. The example application is about as
simple as you can imagine: a modified "Hello Android" application. You'll add a minor modification to make the
screen background color all white so you can use the phone as a flashlight. Not very original, but it will be
useful as an example. Download the full source code.
To create an application in Eclipse, select File > New > Android project, which starts the New Android
Project wizard.
Next, you create a simple application with a single activity, along with a UI layout stored in main.xml. The
layout contains a text element you're going to modify to say Android FlashLight. The simple layout is shown
below.
The main screen layout has a background color defined as all_white. In the strings.xml file, you see that all_white is
defined as an RGB triplet value of #FFFFFF, or all white.
The layout contains a single TextView, which is really just a piece of static text; it is not editable. The text is set to
be black and is centered horizontally with the gravity attribute.
The application has a Java source file called FlashLight.java, as shown below.
Listing 3. Flashlight.java
package com.msi.flashlight;
import android.app.Activity;
import android.os.Bundle;
public class FlashLight extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
The AndroidManifest.xml file setup for the FlashLight application is shown below.
This file was created automatically by the Android Developer Tools plug-in for Eclipse. You didn't have to do
anything.
Of course, the application is not terribly magnificent. But it could come in handy if you want to do some reading
without disturbing your sleeping spouse, or if you need to find your way to the fuse box in the basement during
a power outage.
Summary
In this article, you learned about Android at a very high level and built a small application. Hopefully, the
example got you excited enough to explore more of the Android platform. Android promises to be a market-
moving open source platform that will be useful well beyond cell phones.
Download
Resources
Learn
The Open Handset Alliance is a group of 47 technology and mobile companies who have come together to
accelerate innovation in mobile and offer consumers a richer, less expensive, and better mobile experience.
Together, they have developed Android, the first complete, open, and free mobile platform.
The Android developers site offers documentation, downloads, blogs, and more.
Check out the tutorials hosted on YouTube that discuss the internals of the Dalvik VM.
Unlocking Android: A Developer's Guide provides concise, hands-on instruction for the Android operating
system and development tools.
To listen to interesting interviews and discussions for software developers, check out developerWorks
podcasts.
Check out upcoming conferences, trade shows, webcasts, and other Events around the world that are of
interest to IBM open source developers.
Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates to
help you develop with open source technologies and use them with IBM's products.
Watch and learn about IBM and open source technologies and product functions with the no-cost
developerWorks On demand demos.
Innovate your next open source development project with IBM trial software, available for download or on
DVD.
Download IBM product evaluation versions or explore the online trials in the IBM SOA Sandbox and get
your hands on application development tools and middleware products from DB2®, Lotus®, Rational®,
Tivoli®, and WebSphere®.
Discuss
After his college basketball career came to an end without a multiyear contract to play for the L.A. Lakers,
Frank Ableson shifted his focus to computer software design. He enjoys solving complex problems, particularly
in the areas of communications and hardware interfacing. When not working, he can be found spending time
with his wife Nikki and their children. You can reach Frank at frank@cfgsolutions.com.
Close [x]
developerWorks: Sign in
If you do not have an IBM ID and password, register here.
IBM ID:
Forgot your IBM ID?
Password:
Forgot your password?
Change your password?
Submit Cancel
The first time you sign into developerWorks, a My developerWorks profile is created for you. This profile
includes the first name, last name, and display name contained in the profile you created when you registered
with My developerWorks. Selected information in your My developerWorks profile is displayed to the public, but
you may edit the information at any time. Your first name, last name (unless you choose to hide them), and
display name will accompany the content that you post.
Close [x]
Note: Please choose a display name between 3-31 characters. Your display name must be unique in the
developerWorks community and should not be your email for privacy reasons.
Submit Cancel
1 star 1 star
2 stars 2 stars
3 stars 3 stars
4 stars 4 stars
5 stars 5 stars
Submit
Add comment:
Post
Nice article....
After reading this i developed my own android application
please have a look at this and give me reviews and ratings: http://goo.gl/T8hx2
Regards,
Amit Panchal
http://amitech.co
Report abuse
Report abuse
Report abuse
Just wanted to post a thank you for a very nice ariticle. It help me get my brain around what Android is and is
not. The history section provided a clear understanding why others in the industry are advocating this
technology.
Report abuse