Chapter 4. Intents and Services
This chapter covers
- Asking other programs to do work for you with intents
- Advertising your capabilities with intent filters
- Eavesdropping on other apps with broadcast receivers
- Building Services to provide long-lived background processing
- Offering APIs to external applications through AIDL
You’ve already created some interesting applications that didn’t require a lot of effort to build. In this chapter, we’ll dig deeper into the use of Intent objects and related classes to accomplish tasks. We’ll expand the RestaurantFinder application from chapter 3, and show you how an Intent can carry you from one Activity to another and easily link into outside applications. Next, you’ll create a new weather-reporting application to demonstrate how Android handles background processes through a Service. We’ll wrap up the chapter with an example of using the Android Interface Definition Language (AIDL) to make different applications communicate with one another.
We introduced the Intent in chapter 1. An Intent describes something you want to do, which might be as vague as “Do whatever is appropriate for this URL” or as specific as “Purchase a flight from San Jose to Chicago for $400.” You saw several examples of working with Intent objects in chapter 3. In this chapter, we’ll look more closely at the contents of an Intent and how it matches with an IntentFilter. The RestaurantFinder app will use these concepts to display a variety of screens.