Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 28  Background Services


A service’s intents are called commands. Each command is an instruction to the service to do
something. Depending on the kind of service, that command could be serviced in a variety of ways.


An IntentService service pulls its commands off of a queue, as shown in Figure 28.1.


Figure 28.1  How IntentService services commands


When it receives its first command, the IntentService starts, fires up a background thread, and puts
the command on a queue.


The IntentService then services each command in sequence, calling onHandleIntent(Intent) on its
background thread for each command. New commands that come in go to the back of the queue. When
there are no commands left in the queue, the service stops and is destroyed.


This description only applies to IntentService. Later in the chapter, we will discuss the broader world
of services and how commands work.

Free download pdf