30.04.2013 Views

Android - CommonsWare

Android - CommonsWare

Android - CommonsWare

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 30<br />

Invoking a Service<br />

Services can be used by any application component that "hangs around" for<br />

a reasonable period of time. This includes activities, content providers, and<br />

other services. Notably, it does not include pure broadcast receivers (i.e.,<br />

intent receivers that are not part of an activity), since those will get garbage<br />

collected immediately after each instance processes one incoming Intent.<br />

To use a local service, you need to start the service, get access to the service<br />

object, then call methods on that service. You can then stop the service<br />

when you are done with it, or perhaps let the service stop itself. Using<br />

remote services is somewhat more complex, which is why a discussion of it<br />

is reserved for The Busy Coder's Guide to Advanced <strong>Android</strong> Development<br />

companion volume.<br />

In this chapter, we will look at the client side of the Service/WeatherPlus<br />

sample application. The WeatherPlus activity looks an awful lot like the<br />

original Weather application – just a Web page showing a weather forecast:<br />

377<br />

Subscribe to updates at http://commonsware.com Special Creative Commons BY-SA 3.0 License Edition

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!