Invoking a Service

Services can be used by any application component that "hangs around" for a reasonable period of time. This includes activities, content providers, and other services. Notably, it does not include pure intent receivers (i.e., intent receivers that are not part of an activity), since those will get garbage collected immediately after each instance processes one incoming Intent.

To use a service, you need to get an instance of the AIDL interface for the service, then call methods on that interface as if it were a local object. When done, you can release the interface, indicating you no longer need the service.

In this chapter, we will look at the client side of the MailBuzz sample application (MailBuzz). The MailBuzz activity provides fields for the account information (server type, server, etc.), a checkbox to toggle whether polling for new mail should go on, a button to push the account information to the service, and another button to check right now for new messages.

When run, the activity looks like this:

Login Name:

Password:

Poll Period (mlns): J Enable polling

Poll Period (mlns): J Enable polling

Figure 61. The MailBuzz service client
Self Publishing

Self Publishing

Have you always wanted to write your own book and get it published? Discover How to Write, Print Sell Your Own Book! Have you always wanted to write your own book and get it published? If you have written a book or even if you have a yen to be a writer, you are probably already aware of the competition in the writing field.

Get My Free Ebook


Post a comment