475
Chapter 13
Android Service Class
and Threads: Background
Processing
In the previous chapter on digital audio, you utilized the Android AudioManager class, which is
a subclass of the Android Service class. You also learned about the Android SoundPool and the
SparseIntArray classes. In this chapter, we will take a look at the Android Service classes and
related processing concepts, such as processes and threads.
Developers use the Android Service classes to perform background asynchronous operations.
Asynchronous means that these operations, or more accurately the Java code structures that define
them, can go “off on their own,” and process data streams, or perform complex computation,
in the background. Background Service asynchronous operations can do this without having to
synchronize with your application’s user interface design, which is probably busy controlling how
your application’s content (the user experience) is being presented to your application’s end-users.
Examples of using Android Service subclasses include the playback of long-form digital audio using
the MediaPlayer class while your user is using other areas of the application, talking to servers or
databases in the background, downloading data, managing file input-output streams, streaming
new media content (digital video streams or digital audio streams), handling networking (SMTP and
HTTP) protocol transactions, handling payment gateway transactions, real-time processing of GPS
data, and similar complex computational or data-processing tasks.
This chapter looks closely at the Android Service class and all of the various characteristics
of Android Service classes. We’ll look at how their features, functions, settings, constants, and
characteristics are declared in your Android application. As you may have surmised, declaring
Services for usage is done in the AndroidManifest.xml file, by using the
implement a Service subclass in the HelloUniverse application, as you also might expect!