Information Technology Reference
In-Depth Information
stack-based like the Java VM, but register-based and optimized for resource-
constrained mobile devices [13].
Android applications do not have a single entry-point, such as the main
method in Java. Developers must instead design the application in terms of
components, each one adhering to a set of predefined interfaces. Every com-
ponent is implemented as Java class derived from a specific base class in the
Android middleware. Components react to OS events by overwriting the respec-
tive methods or calling specific OS methods to register further callbacks that
are invoked when e.g. device's physical location changes.
There exist four different kinds of components: activities , services , content
providers ,and broadcast receivers [14]. Activities are single focused activities a
user can interact with. They are the visible parts of an applications. In con-
trast, the services run in the background and are not interacting with the user
directly. They are used for long-running background operations, such as MP3
playback. Broadcast receivers react to global events, such as incoming calls or
text messages. Content providers implement domain-specific databases for, e.g.,
contacts [15].
The first three component types can communicate via asynchronous messages
called intents . An intent is an abstract description of an action “intended” to be
performed, such as “launch the following website” . Intents are a powerful feature
in the Android platform that allow communication between components, both
inside an application and across application boundaries. Intents are dispatched
by the Android middleware, either to a directly specified receipient or to all
receivers registered with the system for a specific intent type, e.g., all components
capable of displaying a website to a user.
Each of the four different types of components have a distinct lifecyle that
defines how the component is created, used and destroyed. The lifecycle is guided
using events, i.e., a sequence of methods called by the OS. For instance, the
onCreate() method gets called when an activity is loaded for the first time [16].
2.2 Android SMS Messenger Example
We next describe a simple Android application implementing an SMS Messenger.
The app's user interface simply consists of two user inputs, one for the phone
number and one for the message to be sent. When the user clicks on the“Send
SMS” button, the application sends the given text message to the given phone
number.
Listing 1.1 shows the corresponding source code. The code comprises the two
methods onCreate and sendSms . As described in Section 2.1, the onCreate event
method gets called when the activity is launched for the first time. The method
defines some layout settings ( setContentView ) and prints out some debug in-
formation. Section 2.5 will give more details on Android's logging infrastructure.
The sendSms callback method is the more interesting part. It is called when
the user clicks on the “Send SMS” button. The link between the method and
the button is established using a layout XML file, which is a declarative way
 
Search WWH ::




Custom Search