The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
One of the problems that we have in Android app development is the overloading
of terms. We have already seen how “layouts” sometimes refer to
layout resources and sometimes refer to container classes like
Another example comes in the name “service”. This was already used in
a few places in Java (e.g.,
ExecutorService). Android then used it
for one of our four app components. Android also
uses “service” as part of the term “system service”… where system
services have little to do with Java services or Android services.
System services are “manager”-type classes that you get by calling
getSystemService() on some
Context, such as an
Usually, system services are tied to lower-level device functionality,
like telephony. However, not all low-level device functionality is exposed
by means of system services; some have separate APIs implemented by
other sorts of “manager” classes.
There are two flavors of
getSystemService(). The one that you are
likely to use is the one that takes a
String parameter that is the
name of the system service that you want. You get back a generic
which you then have to downcast to the specific type of system
service that you are trying to use:
API Level 23 finally added a type-safe version of
You pass in the Java class object for the system service and get an instance
of that class back:
However, until your
minSdkVersion rises to 23 or higher, you will
not be able to use that version of
on older devices.
Alas, there is no backport
ContextCompat from the Android Support
The preview of this section is presently indisposed.