posted 2 years ago in Dev Platform category by Dong Ho Han
Android, currently the most popular mobile operating system in the world, continues to further solidify its position as the major mobile platform in the world. In this article I will briefly cover how Android has appeared, and will explain its software structure and what has to be paid attention when developing apps for this platform.
What is Android?
Linux operating system is the main component in Android's software stack. It does not differ much from Microsoft's Windows OS or Apple's Mac OS which we use on the daily basis. Therefore, theoretically you can enjoy Android not only on mobile devices but also on other tablet devices as well just like Windows even to a point where various applications can be downloaded and used. Of course, if you want to make an Android application by yourself, you should also install ADK (Android Development Kit) to your PC and use Java programming language for development. For a lower level program, NDK (Native Development Kit) for C language shall be used.
It seemed that Android had been shunned publicly for not having as sensitive UI as iPhone. However, now it is considered as the most viable blue-chip mobile OS with advantageous openness, free, and Java-based characteristics.
Another interesting aspect is that most users mistakenly think that Android was developed by Google. In fact, it was developed in 2003 by "Android" company based in California. Back then, few people knew about it, even less developed for it. However, everything was changed in 2005 when Google acquired Android company to give birth to Android that we know now.
The History of Google Android
Since its initial release of 1.0 version in September 23rd, 2008, Android has enjoyed a remarkable growth. All versions until 3.0 (code name Honeycomb) are available under Apache free open source license. According toAndroid official blog, the source code of the Honeycomb series was not released to the public because it was specifically created for tablet computers, and Google did not want external developers to mess up the user interface by putting on smartphones a version of Android intended for tablets.
However, Google later announced that in the next 4.0 version, planned for the second half of this year (code nameIce Cream Sandwitch), Android will combine both the smartphone version (code name Gingerbread) and the tablet version (HoneyComb).
The first version of Android, released back in 2008, had drawbacks in many aspects. Some users voiced their worries about its terrible UI and development tools, saying “who would want to use it”. However with its advantage of using Java as SDK language and its openness Android gradually solidified itself as the most rapidly developing mobile OS, and it seems as if no one dare to challenge the idea that Android will further expand and attract more users than iPhone and be loaded onto more various mobile devices.
The following are the key functions of each Android version
- 2.0, 2.1 (Eclair): Web browser supporting new UI and HTML5. Advanced camera app, new launcher app and weather app. Supports moving background.
- 2.3 (Gingerbread) : Optimized UI for minimum battery use. Enhanced soft keyboard, COPY/PASTE function, NFC (Near Field Communication, local network).
- 3.0 (Honeycomb) : Support tablet screen. New UI and multi-core processor.
- 3.2 (Honeycomb) : Compatible mode for zoom-to-fill screen. Read media file directly from SD card. Additional screen API. Controls UI more delicately.
- 4.0 (Ice Cream Sandwich) : Combined version of Gingerbread and Honeycomb.
The Structure of Android
Android basically runs on DVM (Dalvik Virtual Machine) which is Android runtime loaded on Linux kernel. The figure below illustrates all the components. Further I will explain each of them from top to down.
This domain is for applications developed with Java. Generally, email client, SMS program, calendar, browser and contacts applications are loaded.
Application framework provides all kinds of APIs needed to develop a full-featured application for Android platform. Using APIs in this domain allows to express buttons and text on the screen or use data of other applications such as images and character strings. Also it is possible to manage application’s lifecycle.
This domain provides various C/C++ libraries which can be used on Android. All libraries in this domain can be used by developers via application framework. Standard C system libraries based on BSD (Berkeley Software Distribution) are revised to be suitable for Linux-based devices. Media library based on OpenCore of PacketVideo supports MPEG4, H.264, MP3, AAC, AMR, JPG and PNG files. Surface manager supports 2D and 3D graphics whileWebKit supports browser functions. SQLite is also available as a database engine which can be used by applications.
Although Android is developed in Java language, DVM (Dalvik Virtual Machine) is used instead of JVM (Java Virtual Machine). Thus, a source code (Java) is compiled to a class file (.class) with Java compiler which is later transformed to Dalvik Executable by DX tools. The reason for this is that Dalvik is optimized to run on small sized devices with limited memory.
Android is developed based on Linux kernel 2.6 which provides high security, memory and process management, network stack and various drivers.
Android Project Structure
Android applications are developed in Java. However, unlike the desktop version of Java applications, the class files in Android applications are not loaded directly. Instead Android's development tools combine the resource files and DEX file transformed from class file to make APK. And this APK gets loaded.
Below is the basic directory structure for developing the Android application.
|/assets||Data files to be installed to device along with the application.|
|/bin||Compiled application file.|
|/gen||Resource reference files automatically created by the Android build system.|
|/res||Resource files such as character strings and images to be used in the application.|
|/src||Application source code.|
|AndroidManifest.xml||Basic set file of application.|
You need to make sure that files are stored in the right directory, particularly for resources. Since directories are already reserved, changing at your will would make directories difficult to recognize.
Resource directory is composed of drawable directory for placing images and layout directory for putting the XML files to the layout. Raw and xml directories are not automatically created in the default project, so should be created manually.
|/res/drawable-hdpi||Image to be shown on hdpi.|
|/res/drawable-ldpi||Image to be shown on ldpi.|
|/res/drawable-mdpi||Image to be shown on mdpi.|
|/res/drawable-nodpi||Image to be shown regardless of density.|
|/res/layout/||XML file defining UI layout.|
|/res/layout-port/||XML file defining UI layout (vertical mode).|
|/res/layout-land/||XML file defining UI layout (horizontal mode).|
|/res/menu/||XML file defining menus.|
|/res/values/||File defining various values such as character strings.|
|/res/xml/||Various files saved in the form of XML.|
|/res/raw/||Other files (mp3, mp4 and so on).|
The vertical and horizontal mode differs in size on the phone screen. Therefore, if you need both of them to be shown identically, you need to create screen layout file on /res/layout/ directory. To show differently, create the layout in the layout-port (portrait) and layout-land (landscape) directories. Also, often you may need to create a layout and layout-land only. Then files in layout will be applied to vertical mode layout.
The structure of bin (result) directory is as follows.
|bin/classes/||Compiled Java class.|
|bin/classes.dex||Dalvik class file created with compiled Java class.|
|bin/resources.ap_||All resource files (zip) of application.|
|bin/app_name.apk||Android application (zip).|
Files that end with “.apk” are the final outcome of Android project, thereby they are ready to be registered in the Android market. The compressed format of this file is zip, which allow us to easily open with compressing programs. However opening this file will not let you decode the meaning since the source files are already compiled.
AndroidManifest.xml file is a very important file holding information about the overall structure of the application. Through this file, the Android system finds out component kinds and intent filter and later checks the authority.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.androidside" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".HelloWorld" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="9" /> <!-- android 2.3 --> </manifest>
AndroidManifest.xml can declare the following elements.
|<uses-permission />||Authority required by the Application.|
|<permission />||Authority required by external activity or service.|
|<instrumentation />||During the occurrence of key events such as activity run, it designates what to call in the application (record, monitoring).|
|<uses-library />||Designate additional necessary libraries (Google maps).|
|<uses-sdk />||Android version required for application.|
|<application />||Application-related information.|
Elements and Structure of Android Application
Android has 4 key components:
- Broadcast Receiver
- And Content Provider
These four components can be closely connected using Intent. Below are the key terms and 4 components for Android. Knowing below words will help you understand better Android.
Android Key Terminology
|Activity||Component for composing UI.|
|Service||Component that runs on the background. No visual UI.|
|Intent||Message element which sends action and data to components.|
|Intent Filter||Defines component by setting intent for receiving.|
|Broadcast Receiver||Receives/responds to a certain broadcast such as lack of battery, language setting/changing. No visual UI.|
|Content Provider||Provides standardized interface for sharing data among applications.|
|Notification||Notifying a certain event to user.|
There are various kinds of components for Android, but development using these elements can be described in MVC structure.
View is for screen composition and this domain can be composed by using the class which inherits View class provided by Android.
This domain is for connecting and controlling VIEW and MODEL. Activity, Service and BrodacastReceiver are included.
This domain is for storing application’s data. SQLite, an embedded database system in Android, File and Content Provider, which can be used for sharing data among applications, are included.
Java SDK is, perhaps, one of the most important advantages of Android which provides various powerful functions of Java programming language. However, many developers complain about Android's fast development pace that they have difficulties to catch up. But if we think more positively, this fast-paced transformation seems to have materialized Android to consolidate itself as the most popular mobile platform. On top of that this popularity has led to many patent suits with Microsoft, thus pressuring many carrier providers to inevitably pay patent fees who initially used the technology thinking it was free. Also Oracle’s patent suit against Google citing that Java cannot be used on mobile devices just because Android uses Java. For above reasons and more, the future path of Android might not seem as smooth as before, but we can’t say it will be gloomy either. I hope all these issues will be settled down, and Android will continue to prosper.
By Dong Ho Han, Web Platform Development Lab, NHN Corporation.