Skip to content

Most visited

Recently visited


Sending Work Requests to the Background Service

This lesson teaches you to

  1. Create and Send a Work Request to an IntentService

You should also read

Try it out

Download the sample

The previous lesson showed you how to create an IntentService class. This lesson shows you how to trigger the IntentService to run an operation by sending it an Intent. This Intent can optionally contain data for the IntentService to process. You can send an Intent to an IntentService from any point in an Activity or Fragment

Create and Send a Work Request to an IntentService

To create a work request and send it to an IntentService, create an explicit Intent, add work request data to it, and send it to IntentService by calling startService().

The next snippets demonstrate this:

  1. Create a new, explicit Intent for the IntentService called RSSPullService.
     * Creates a new Intent to start the RSSPullService
     * IntentService. Passes a URI in the
     * Intent's "data" field.
    mServiceIntent = new Intent(getActivity(), RSSPullService.class);
  2. Call startService()
    // Starts the IntentService

Notice that you can send the work request from anywhere in an Activity or Fragment. For example, if you need to get user input first, you can send the request from a callback that responds to a button click or similar gesture.

Once you call startService(), the IntentService does the work defined in its onHandleIntent() method, and then stops itself.

The next step is to report the results of the work request back to the originating Activity or Fragment. The next lesson shows you how to do this with a BroadcastReceiver.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)