Report work status

This guide shows you how to report the status of a work request run in a background service
to the component that sent the request. This allows you, for example, to report the status of
the request in an Activity object's UI. The recommended way to send and
receive status is to use a LocalBroadcastManager, which
limits broadcast Intent objects to components in your own app.

Report status from a JobIntentService

To send the status of a work request in an
JobIntentService to other
components, first create an Intent that contains the status in its
extended data. As an option, you can add an action and data URI to this
Intent.

Once you've defined the BroadcastReceiver, you can define filters
for it that match specific actions, categories, and data. To do this, create
an IntentFilter. This first snippet shows how to define the filter:

Java

/*
* Instantiates a new action filter.
* No data filter is needed.
*/
statusIntentFilter = new IntentFilter(Constants.ACTION_ZOOM_IMAGE);
// Registers the receiver with the new filter
LocalBroadcastManager.getInstance(this).registerReceiver(
mDownloadStateReceiver,
statusIntentFilter);

Sending an broadcast Intent doesn't start or resume an
Activity. The BroadcastReceiver for an
Activity receives and processes Intent objects even
when your app is in the background, but doesn't force your app to the foreground. If you
want to notify the user about an event that happened in the background while your app was not
visible, use a Notification. Never start an
Activity in response to an incoming broadcast
Intent.

Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.