Chapter 3
Services
In This Chapter
Running code without bothering the user
Running code when a device starts
Starting, binding, and querying
Sending messages from one process to another
Some things are of no concern to the user of an Android device. Imagine seeing a pop-up message saying, “A process on your phone is checking for email right now,” followed immediately by the message, “Nope, no new email. Sorry about the interruption. Get back to what you were doing. You’ll hear from me again in exactly one minute.” One of my phones actually did this! Such notices are intrusive and unnecessary, especially on a device with limited screen real estate.
To do something behind the scenes, you don’t want an Android activity. An activity normally has a layout file, and the user deals with the layout’s gizmos on the screen. Instead, you want the kind of component that runs quietly in the background. In other words, you want an Android service.
A Very Simple Service
I start this chapter with an embarrassingly simple example — a service that doesn’t do anything. This lazy service simply illustrates ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access