Chapter 13. System Services

Like many modern operating systems, Android comes with a number of system services that are always on, always running, and readily available for developers to tap into. These system services include things like the Location service, Sensor service, WiFi service, Alarm service, Telephony service, Bluetooth service, and so on. System services are started at boot time and are guaranteed to be running by the time your application launches.

In this chapter, we’ll see how we can use some of the system services to further expand the Yamba application. First, we’ll take a look at the Sensor service in a small example to demonstrate some of the concepts that are common to most of the system services. Then, we’ll add support for location information to our status updates via the Location service.

Additionally, we’re going to refactor the Yamba application to take advantage of Intent Service support. This will demonstrate how to use the Alarm service and will make our Updater slightly simpler and more efficient.

Compass Demo

To start with system services, we are going to look at a simple, self-contained example of a compass application. This application uses the Sensor service to get updates from the orientation sensor and use its information to rotate a Rose, our custom UI component. The Sensor service is very typical of system services and a relatively easy one to understand.

To build this example, we’ll create an activity that will get the Sensor service and register ...

Get Learning Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.