Mobile Phone Handheld Hardware Hardware Rick Rogers John Lombardo O'Reilly Media, Inc. O'Reilly Media Android Application Development, 1st EditionChapter 13. Inter-Process CommunicationAndroid is designed to host a variety of applications and to maximize
user choice. The platform is intended to eliminate the duplication of
functionality in different applications, to allow functionality to be
discovered and invoked on the fly, and to let users replace applications
with others that offer similar functionality. Applications must have as few
dependencies as possible, and must be able to contract out operations to
other applications that may change at the user's discretion. Inter-process communication (IPC) is thus the basis of key features of
the Android programming model. The techniques we'll look at in this chapter
are:
Intents These enable an application to select an Activity based on the
action you want to invoke and the data on which they operate. In other
words, you don't need a hardcoded path to an application to use its
functions and exchange data with it. Data can be passed in both
directions using Intent objects, and this enables a
convenient, high-level system of inter-process communication.
Remote methods This feature resembles the remote procedure calls (RPCs) offered by
other systems: it makes APIs accessible remotely. Remote objects allow
you to make method calls that look "local" but are executed in another
process. They involve the use of Android's interface definition language (AIDL).
In this chapter, we will see how these features work and how they can
be used in applications. Android applications could avoid inter-process communication and
provide functions in packages loaded by the applications that need them. If
applications had to exchange data, they could use the filesystem or other
traditional Unix/Linux IPC mechanisms (sockets, shared memory, etc.). But
these practices are error prone and hard to maintain. In particular, some of
the problems include: Libraries are difficult to share among multiple Java processes.
Java was designed to have threads, not processes, share common code
resources. Sharing address space easily leads to errors and inappropriate
access to private data.
Consequently, modern programming environments have moved on to more
robust component-like systems. Intents and remote methods fit the bill
excellently for Android.
|