Android Developer's Cheat

by Stephane Micheloud, August 2010

[Home]
[Back]

An Android application is defined using one or more of Android's four core application components:

When an application starts, the Android system starts a new Linux process for the application with a single thread of execution. By default, all components of the same application run in the same process and thread (called the main thread).

Once installed on a device, each Android application lives in its own security sandbox:

The Android system places each process into an "importance hierarchy" based on the components running in the process and the state of those components. There are five types of processes (processes with the lowest importance are eliminated first):

  1. Foreground process
  2. Visible process
  3. Service process
  4. Background process
  5. Empty process (does not hold any active application components, used e.g. for caching purposes)

UI Thread

The main thread is in charge of dispatching events to the appropriate user interface widgets, including drawing events. As such, the main thread is commonly called the UI thread.

Since the Android UI toolkit is not thread-safe all manipulations to the user interface must be performed from the UI thread. Thus, there are simply two rules to Android's single thread model:

Activities

An activity provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. It can start other activities, including activities that live in separate applications.

Services

A service typically performs long-running operations in the background without a user interface. For example, a service can handle network transactions, play music, or work with a content provider without the user being aware of the work going on.

The hosting process of a started Service is considered to be less important than any processes that are currently visible to the user on-screen.

The most important callback methods you should override are:

Examples: SimpleBinderExample (from "Unlocking Android" book).

Content Providers

A content provider manages a shared set of application data. Data are stored either in the file system, an SQLite database, on the web, or any other persistent storage location the application can access.

Three informations are needed to query a content provider:

A query returns a set of zero or more database records with a unique numeric ID for each record.

Acronysms

ANR application not responding
IPC interprocess communication
RPC remote procedure call
URI uniform resource identifier
VM virtual machine