Android

Android is a mobile operating system based on a Linux kernel (along with several standard applications) designed by Google that utilizes an optimized JVM to run Java programs. It has built-in support for

The Android developers site provides extensive documentation regarding the SDK as well as command references, tutorials, Android conference videos, and forums to discuss Android related issues.

Applications

Android applications are written in Java and are compiled into a special package (with a .apk) extension which is loaded onto the device. Each application is sandboxed such that it runs in its own process and only has access to resources included in the .apk file or made available by the system (such as contacts).

Android applications utilize four types of components depending on the desired functionality and lifetime of the component:

Applications can expose any of their components for other applications to utilize, e.g. the camera app on the phone allows other applications to start its activity to capture pictures. To activate another application's components (since each application is sandboxed), your application generates a message known as an Intent which specifies the type of component you wish to use and the desired action to perform. Then any application that is designed to handle the Intent is able to process the request and possibly respond to the original application via another Intent object.

In order to tell the Android system which components an application will use, an XML file known as the manifest (in the AndroidManifest.xml) is created. It specifies:

For example, a basic application manifest might be

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="edu.ycp.cs.helloandroid"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".HelloAndroid"
            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>

</manifest>

Lifecycle

An important consideration in mobile applications is the lifecycle of the application. Since often times an application will be unloaded at any time by the user, e.g. to take a phone call, or by the system, e.g. due to low memory, it is important to consider how to suspend, destroy, and restore the current state of applications. The simplest way is to simply let the application get destroyed in which case the application will start fresh each time. However this approach can be annoying to users when whatever information they may have entered or were viewing are lost each time they select the application.

A better way is to use methods provided by the component classes to save the current state in some type of persistent manner that can be reloaded when the application is subsequently used. There are a variety of ways Android applications can store persistent data, e.g. SQLite databases, native files, etc., and which one to use is dependent on the information that needs to be stored by the application. Later in the course we will discuss how to handle the volitility of the application state when we investigate creating good UI's.