# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Nested Classes | Ctors | Methods | Inherited Methods

# BroadcastReceiver

`public abstract class BroadcastReceiver`
`extends Object` ``

java.lang.Object
↳ | android.content.BroadcastReceiver

Known direct subclasses AppWidgetProvider, DelegatedAdminReceiver, DeviceAdminReceiver, MbmsDownloadReceiver, PackageChangeReceiver, RestrictionsReceiver
AppWidgetProvider | A convenience class to aid in implementing an AppWidget provider.
DelegatedAdminReceiver | Base class for delegated apps to handle callbacks related to their delegated capabilities.
DeviceAdminReceiver | Base class for implementing a device administration component.
MbmsDownloadReceiver | The `BroadcastReceiver` responsible for handling intents sent from the middleware.
PackageChangeReceiver | Helper class for monitoring the state of packages: adding, removing, updating, and disappearing and reappearing on the SD card.
RestrictionsReceiver | Abstract implementation of a Restrictions Provider BroadcastReceiver.

Base class for code that receives and handles broadcast intents sent by `Context.sendBroadcast(Intent)`.

You can either dynamically register an instance of this class with `Context#registerReceiver` or statically declare an implementation with the `<receiver>` tag in your `AndroidManifest.xml`.

### Developer Guides

For more information about using BroadcastReceiver, read the Broadcasts developer guide.

## Summary

### Nested classes
`class` | `BroadcastReceiver.PendingResult` State for a result that is pending for a broadcast receiver.

### Public constructors
`BroadcastReceiver()`

### Public methods
`final void` | `abortBroadcast()` Sets the flag indicating that this receiver should abort the current broadcast; only works with broadcasts sent through `Context#sendOrderedBroadcast(Intent, String)`.
`final void` | `clearAbortBroadcast()` Clears the flag indicating that this receiver should abort the current broadcast.
`final boolean` | `getAbortBroadcast()` Returns the flag indicating whether or not this receiver should abort the current broadcast.
`final boolean` | `getDebugUnregister()` Return the last value given to `setDebugUnregister(boolean)`.
`final int` | `getResultCode()` Retrieve the current result code, as set by the previous receiver.
`final String` | `getResultData()` Retrieve the current result data, as set by the previous receiver.
`final Bundle` | `getResultExtras(boolean makeMap)` Retrieve the current result extra data, as set by the previous receiver.
`final BroadcastReceiver.PendingResult` | `goAsync()` This can be called by an application in `onReceive(Context, Intent)` to allow it to keep the broadcast active after returning from that function.
`final boolean` | `isInitialStickyBroadcast()` Returns true if the receiver is currently processing the initial value of a sticky broadcast -- that is, the value that was last broadcast and is currently held in the sticky cache, so this is not directly the result of a broadcast right now.
`final boolean` | `isOrderedBroadcast()` Returns true if the receiver is currently processing an ordered broadcast.
`abstract void` | `onReceive(Context context, Intent intent)` This method is called when the BroadcastReceiver is receiving an Intent broadcast.
`IBinder` | `peekService(Context myContext, Intent service)` Provide a binder to an already-bound service.
`final void` | `setDebugUnregister(boolean debug)` Control inclusion of debugging help for mismatched calls to `Context#registerReceiver(BroadcastReceiver, IntentFilter)`.
`final void` | `setOrderedHint(boolean isOrdered)` For internal use, sets the hint about whether this BroadcastReceiver is running in ordered mode.
`final void` | `setResult(int code, String data, Bundle extras)` Change all of the result data returned from this broadcasts; only works with broadcasts sent through `Context#sendOrderedBroadcast(Intent, String)`.
`final void` | `setResultCode(int code)` Change the current result code of this broadcast; only works with broadcasts sent through `Context#sendOrderedBroadcast(Intent, String)`.
`final void` | `setResultData(String data)` Change the current result data of this broadcast; only works with broadcasts sent through `Context#sendOrderedBroadcast(Intent, String)`.
`final void` | `setResultExtras(Bundle extras)` Change the current result extras of this broadcast; only works with broadcasts sent through `Context#sendOrderedBroadcast(Intent, String)`.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.

## Public constructors

### BroadcastReceiver

    public BroadcastReceiver ()

## Public methods

### abortBroadcast

    public final void abortBroadcast ()

Sets the flag indicating that this receiver should abort the current broadcast; only works with broadcasts sent through `Context#sendOrderedBroadcast(Intent, String)`. This will prevent any other broadcast receivers from receiving the broadcast. It will still call `onReceive(Context, Intent)` of the BroadcastReceiver that the caller of `Context#sendOrderedBroadcast(Intent, String)` passed in.

This method does not work with non-ordered broadcasts such as those sent with `Context#sendBroadcast(Intent)`

### clearAbortBroadcast

    public final void clearAbortBroadcast ()

Clears the flag indicating that this receiver should abort the current broadcast.

### getAbortBroadcast

    public final boolean getAbortBroadcast ()

Returns the flag indicating whether or not this receiver should abort the current broadcast.

Returns
`boolean` | True if the broadcast should be aborted.

### getDebugUnregister

    public final boolean getDebugUnregister ()

Return the last value given to `setDebugUnregister(boolean)`.

Returns
`boolean` |

### getResultCode

    public final int getResultCode ()

Retrieve the current result code, as set by the previous receiver.

Returns
`int` | int The current result code.

### getResultData

    public final String getResultData ()

Retrieve the current result data, as set by the previous receiver. Often this is null.

Returns
`String` | String The current result data; may be null.

### getResultExtras

    public final Bundle getResultExtras (boolean makeMap)

Retrieve the current result extra data, as set by the previous receiver. Any changes you make to the returned Map will be propagated to the next receiver.

Parameters
`makeMap` | `boolean`: If true then a new empty Map will be made for you if the current Map is null; if false you should be prepared to receive a null Map.

Returns
`Bundle` | Map The current extras map.

### goAsync

    public final BroadcastReceiver.PendingResult goAsync ()

This can be called by an application in `onReceive(Context, Intent)` to allow it to keep the broadcast active after returning from that function. This does not change the expectation of being relatively responsive to the broadcast, but does allow the implementation to move work related to it over to another thread to avoid glitching the main UI thread due to disk IO.

As a general rule, broadcast receivers are allowed to run for up to 10 seconds before they system will consider them non-responsive and ANR the app. Since these usually execute on the app's main thread, they are already bound by the ~5 second time limit of various operations that can happen there (not to mention just avoiding UI jank), so the receive limit is generally not of concern. However, once you use `goAsync`, though able to be off the main thread, the broadcast execution limit still applies, and that includes the time spent between calling this method and ultimately `PendingResult#finish()`.

If you are taking advantage of this method to have more time to execute, it is useful to know that the available time can be longer in certain situations. In particular, if the broadcast you are receiving is not a foreground broadcast (that is, the sender has not used `Intent#FLAG_RECEIVER_FOREGROUND`), then more time is allowed for the receivers to run, allowing them to execute for 30 seconds or even a bit more. This is something that receivers should rarely take advantage of (long work should be punted to another system facility such as `JobScheduler`, `Service`, or see especially `JobIntentService`), but can be useful in certain rare cases where it is necessary to do some work as soon as the broadcast is delivered. Keep in mind that the work you do here will block further broadcasts until it completes, so taking advantage of this at all excessively can be counter-productive and cause later events to be received more slowly.

Returns
`BroadcastReceiver.PendingResult` | Returns a `PendingResult` representing the result of the active broadcast. The BroadcastRecord itself is no longer active; all data and other interaction must go through `PendingResult` APIs. The `PendingResult#finish` method must be called once processing of the broadcast is done.

### isInitialStickyBroadcast

    public final boolean isInitialStickyBroadcast ()

Returns true if the receiver is currently processing the initial value of a sticky broadcast -- that is, the value that was last broadcast and is currently held in the sticky cache, so this is not directly the result of a broadcast right now.

Returns
`boolean` |

### isOrderedBroadcast

    public final boolean isOrderedBroadcast ()

Returns true if the receiver is currently processing an ordered broadcast.

Returns
`boolean` |

### onReceive

    public abstract void onReceive (Context context,
                    Intent intent)

This method is called when the BroadcastReceiver is receiving an Intent broadcast. During this time you can use the other methods on BroadcastReceiver to view/modify the current result values. This method is always called within the main thread of its process, unless you explicitly asked for it to be scheduled on a different thread using `Context.registerReceiver(BroadcastReceiver, IntentFilter, String, android.os.Handler)`. When it runs on the main thread you should never perform long-running operations in it (there is a timeout of 10 seconds that the system allows before considering the receiver to be blocked and a candidate to be killed). You cannot launch a popup dialog in your implementation of onReceive().

If this BroadcastReceiver was launched through a <receiver> tag, then the object is no longer alive after returning from this function. This means you should not perform any operations that return a result to you asynchronously. If you need to perform any follow up background work, schedule a `JobService` with `JobScheduler`. If you wish to interact with a service that is already running and previously bound using `bindService()`, you can use `peekService(Context, Intent)`.

The Intent filters used in `Context.registerReceiver(BroadcastReceiver, IntentFilter)` and in application manifests are not guaranteed to be exclusive. They are hints to the operating system about how to find suitable recipients. It is possible for senders to force delivery to specific recipients, bypassing filter resolution. For this reason, `onReceive()` implementations should respond only to known actions, ignoring any unexpected Intents that they may receive.

Parameters
`context` | `Context`: The Context in which the receiver is running.
`intent` | `Intent`: The Intent being received.

### peekService

    public IBinder peekService (Context myContext,
                    Intent service)

Provide a binder to an already-bound service. This method is synchronous and will not start the target service if it is not present, so it is safe to call from `onReceive(Context, Intent)`. For peekService() to return a non null `IBinder` interface the service must have published it before. In other words some component must have called `Context.bindService(Intent, ServiceConnection, int)` on it.

Parameters
`myContext` | `Context`: The Context that had been passed to `onReceive(android.content.Context, android.content.Intent)`
`service` | `Intent`: Identifies the already-bound service you wish to use. See `Context.bindService(Intent, ServiceConnection, int)` for more information.

Returns
`IBinder` |

### setDebugUnregister

    public final void setDebugUnregister (boolean debug)

Control inclusion of debugging help for mismatched calls to `Context#registerReceiver(BroadcastReceiver, IntentFilter)`. If called with true, before given to registerReceiver(), then the callstack of the following `Context#unregisterReceiver(BroadcastReceiver)` call is retained, to be printed if a later incorrect unregister call is made. Note that doing this requires retaining information about the BroadcastReceiver for the lifetime of the app, resulting in a leak -- this should only be used for debugging.

Parameters
`debug` | `boolean`

### setOrderedHint

    public final void setOrderedHint (boolean isOrdered)

For internal use, sets the hint about whether this BroadcastReceiver is running in ordered mode.

Parameters
`isOrdered` | `boolean`

### setResult

    public final void setResult (int code,
                    String data,
                    Bundle extras)

Change all of the result data returned from this broadcasts; only works with broadcasts sent through `Context#sendOrderedBroadcast(Intent, String)`. All current result data is replaced by the value given to this method.

This method does not work with non-ordered broadcasts such as those sent with `Context#sendBroadcast(Intent)`

Parameters
`code` | `int`: The new result code. Often uses the Activity `Activity.RESULT_CANCELED` and `Activity.RESULT_OK` constants, though the actual meaning of this value is ultimately up to the broadcaster.
`data` | `String`: The new result data. This is an arbitrary string whose interpretation is up to the broadcaster; may be null.
`extras` | `Bundle`: The new extra data map. This is a Bundle holding arbitrary data, whose interpretation is up to the broadcaster. Can be set to null. This completely replaces the current map (if any).

### setResultCode

    public final void setResultCode (int code)

Change the current result code of this broadcast; only works with broadcasts sent through `Context#sendOrderedBroadcast(Intent, String)`. Often uses the Activity `Activity.RESULT_CANCELED` and `Activity.RESULT_OK` constants, though the actual meaning of this value is ultimately up to the broadcaster.

This method does not work with non-ordered broadcasts such as those sent with `Context#sendBroadcast(Intent)`

Parameters
`code` | `int`: The new result code.

See also:

- `setResult(int, String, Bundle)`

### setResultData

    public final void setResultData (String data)

Change the current result data of this broadcast; only works with broadcasts sent through `Context#sendOrderedBroadcast(Intent, String)`. This is an arbitrary string whose interpretation is up to the broadcaster.

This method does not work with non-ordered broadcasts such as those sent with `Context#sendBroadcast(Intent)`

Parameters
`data` | `String`: The new result data; may be null.

See also:

- `setResult(int, String, Bundle)`

### setResultExtras

    public final void setResultExtras (Bundle extras)

Change the current result extras of this broadcast; only works with broadcasts sent through `Context#sendOrderedBroadcast(Intent, String)`. This is a Bundle holding arbitrary data, whose interpretation is up to the broadcaster. Can be set to null. Calling this method completely replaces the current map (if any).

This method does not work with non-ordered broadcasts such as those sent with `Context#sendBroadcast(Intent)`

Parameters
`extras` | `Bundle`: The new extra data map; may be null.

See also:

- `setResult(int, String, Bundle)`

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*