Dr Rajesh Vasa17 September 2011, 11:48 AM
With 500,000 activations a day, Android is becoming the dominant player in the mobile eco-system, now powering the majority of mobile devices sold.
So, what is Android? How does one start developing for this platform? This masterclass introduces Android from a development perspective, and guides you to setup the development environment. In order to up hold the programmer’s tradition, we will build a “Hello World” application and run it in an emulator.
Android is a platform designed for mobile devices that includes a customised Linux kernel, frameworks, libraries and commonly used applications. The Linux kernel manages the hardware and provides security, resource/file/process management, networking and drivers. A range of libraries sit on top of this kernel to provide functionality such as media playback, 2D/3D graphics, font rendering, data management, and web page rendering.Figure 1: The Android software stack has a number of different components.
Android unlike most other mobile platforms is completely open, allowing complete access for anyone with the relevant programming skills to build and deploy applications. In fact you can deploy an application to your Android phone over a USB cable — no special permissions, certificates or extra rights needed. The freely available development kit provides full access to most of the hardware sensors and software libraries/frameworks that are part of the platform.
Developers have access to a powerful UI layout engine, a local database management system, a locale-aware resource manager for organising graphical/media/string assets, a notification manager to organise internal and external notifications, a powerful life cycle manager to manage the various processes created as part of an application, and an extensive graphics sub-system to build games. Here is a more in-depth description of the Android platform.
Android Device Hardware and the Interaction Model
Android devices have a minimum of 3 functional buttons unlike the iPhone, which has a single physical button. Android devices have a Home, Back and Menu button. The Home button returns the user to the main phone screen — it is very similar in functionality to the iPhone’s. The menu button permits contextual menus to be added to any screen. The Back button has functionality similar to the back button on a web browser, and takes the user back to the previous screen. In terms of usability, the back button is considered to be effective on a mobile device. Although many applications on Android make use of the Menu button, the options provided in this menu need to be discovered by the user — they literally have to press the menu button on the various screens of an application in order to find the options available within the contextual menus.
The Android platform permits hardware vendors to create additional buttons including keyboards and have different form factors with screens of different sizes — there are even differentiations in terms of the availability of the sensors. This rather generous policy has resulted in the hardware vendors creating a broad range of devices requiring software developers to design software that can cope with this fragmented and diverse world. Thankfully, the Android software development framework is designed to deal with a hardware eco-system that is diverse and continuously evolving. One specific approach the framework uses is to allow developers to tag an application with the hardware/software features required in a target phone.
Android platform is still evolving
The platform is still rapidly evolving with a new major release posted nearly every 6 months. In a way, Android is just like Windows with a range of different versions in active use. Currently most mobile devices run either version 2.1 or 2.2 release of the Android platform (fortnightly reports on usage are posted here by Google ). Newer models often use the 2.3 release, while the newly announced Android tablets run the 3.x release which is designed for the larger screen real-estate that is available on those devices.
Applications are forward-compatible (i.e. If developed for 2.1, they will run fine on 2.2 and 2.3), but are not backward compatible. Although, the platform is open source and freely available, most users do not have sufficient technical knowledge, or the desire to update the operating environment — just like most of us not updating the firmware in the fridge. Sadly, to ensure the application is available to a sufficiently large market, developers have to currently target Android 2.2 release. In this masterclass series, release 2.2 will be the assumed primary target.
Android and Java
Android is a bi-lingual platform. Developers have the choice of using either Java or C/C++ as their primary programming language of choice. However, in practice most of the applications are currently built in Java using the Eclipse IDE. The tooling, documentation, and online community support is also built for programming in Java.
Android developers made two critical changes to the Java environment to ensure that it works well on a mobile device. First, they opted to use the Dalvik virtual machine with optimisations for a mobile device rather than the Oracle/Sun Java Virtual Machine technology. Secondly, they rebuilt the standard library and have intentionally omitted many parts that are found in the Oracle/Sun Java. In a nutshell, they eliminated much of the bloat and provided a library/framework that runs smoothly even on an older generation mobile device — especially, for the UI and graphics library.
Java - A Short Overview
Java is a platform that offers a programming language and an extensive standard library/framework to help develop desktop, browser and web applications. The language has a C-like syntax, is object-oriented, and these days is mostly used to develop web applications and back-end enterprise systems. The strength of Java lies primarily in the standard library, its ability to connect with many existing systems, and the availability of a large pool of reliable open-source third-party libraries. Unlike scripting languages like Perl/PHP, programs written in Java are compiled into an intermediate representation, called the bytecode. An operating system specific virtual machine executes this bytecode when we run a Java program. The initial releases of Java were often considered (with good reason) to be slow, but recent optimisations to the virtual machine technology makes Java programs run almost as well as native code.
Next: Setting up the Android development environment