
Let's take a moment to examine the four main types of Android applications: activity,
services, receivers, and ContentProvider. We will also take a look at the views to
display the user-interface (UI) elements.
Activity
The activity is the most visible and prominent form of an Android application. An
activity presents the UI to an application, along with the assistance of a class known
as a view. The view class is implemented as various UI elements, such as text
boxes, labels, buttons, and other UIs typical in computing platforms, mobile or
otherwise.
An application may contain one or more activities. They are typically on a one-to-one
relationship with the screens found in an application.
An application moves from one activity to another by calling a method known as
startActivity() or startSubActivity(). The former method is used when
the application desires to simply "switch" to the new activity. The latter is used when
a synchronous call/response paradigm is desired. In both cases, an intent is passed
as an argument to the method.
It is the operating system's responsibility to determine the best-qualified activity to
satisfy the specified intent.
Services and receivers
Like other multitasked computing environments, there are applications running "in
the background" that perform various duties. Android calls these types of
applications "services." The service is an Android application that has no UI.
The receiver is an application component that receives requests to process intents.
Like the service, a receiver does not, in normal practice, have a UI element.
Receivers are typically registered in the AndroidManifest.xml file. The snippet shown
in Listing 1 is an example of a receiver application. Note that the class attribute of
the receiver is the Java class responsible for implementing the receiver. Listing 2 is
an example of receiver code.
Listing 2. Receiver code
package com.msi.samplereceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentReceiver;
developerWorks® ibm.com/developerWorks
Develop Android applications with Eclipse
Page 6 of 35 © Copyright IBM Corporation 1994, 2008. All rights reserved.
Kommentare zu diesen Handbüchern