JVM Languages

The Android Mobile Phone Platform

Source Code Accompanies This Article. Download It Now.

Android is an open-source mobile phone stack developed by Google for the Open Handset Alliance.

"I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone."

Bjarne Stroustrup

At 25 years of age, you might think that the mobile phone has grown up. However, it's about to undergo some dramatic changesa delayed adolescence, if you will. Specifically, its software is about to undergo an overhaul. New, upstart players in the market want to revamp its entire software stack, with attention on its UI. Such changes will be welcomed by mobile phone users, becauseas Bjarne Stroustrup attestsmany of these devices have uniformly awful UIs. It's not altruism on these companies' part that motivates this effort, but a lucrative market of more than a billion subscribers that's growing rapidly.

With the launch of its iPhone in 2007, Apple quick-started the mobile phone's makeover. While the existing playersNokia's Symbian, Sun's Java Micro Edition (Java ME, formerly known as "Java 2 Micro Edition," or J2ME), and Microsoft's Windows Mobilearen't standing still, such a disruptive change also provides an opportunity for new players to enter the field. Google has done just that with Android, its own mobile phone platform (code.google.com/android). Android uses Java and its application frameworks are Java-based, which offers the intriguing possibility of porting field-tested Java ME applications to it.

This Is the Droid You're Looking For

Android is a mobile phone stack developed by Google for the Open Handset Alliance (www.openhandsetalliance.com). Android is open source, and draws on open-source projects such as Linux, WebKit, SQLite, and FreeType to implement its core services.

Figure 1 shows the Android software stack. At the stack's bottom and closest to the silicon, a Linux 2.6 kernel provides preemptive multitasking and system services such as threads, networking services, plus memory and process management. It manages all low-level drivers and acts as a Hardware Abstraction Layer (HAL). Any low-level device accesses should be handled through the Android frameworks and not Linux command-line utilities.

Above the kernel is the Android runtime and support libraries layer. The runtime consists of the Dalvik Virtual Machine (DVM) and core libraries. The DVM is a bytecode interpreter that provides device independence for Android applications, similar in purpose to Java ME's JVM. Like the JVM, Google's DVM is optimized for embedded systems. For example, it uses register-based calls and storage, reducing the overhead incurred using stack operations. Furthermore, the core libraries that implement Java capabilities are written in native code. Importantly, a device can execute multiple instances of the DVM, with each running an Android process. Because each Android application executes in its own process, a device can therefore execute multiple Android applications concurrently. However, it's important to note that Android is optimized for use on a single screen.

Figure 1: Android software stack.

The support libraries are written in C/C++ and provide a range of system services. All are from open-source projects: SQLite provides lightweight relational database services, SGL handles 2D vector graphics, and WebKit (which is at the heart of Apple's Safari browser) implements a web browser engine. An Android application can access the stack's filesystem, but not the files used by other Android applications.

The Application Frameworks occupy the next layer on the stack. These are Java-based, and provide a rich set of services for a mobile application. For example:

Activity Manager handles all of the details of an Android application's lifecycle, including a mechanism to assist in preserving its state.

View System manages many of the UI elements, including handling user events.

Resource Manager handles the resources, such as graphics files and message strings, that the application's UI requires.

Location Manager obtains the device's position.

Telephony Manager handles making and receiving phone calls.

These frameworks let you, through inheritance, either modify a class's behavior or extend its capabilities.

Android's Application Layer will be populated with applications, including a web browser, calendar, e-mail client, and map displayall written in Java.

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task.
However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!