Android Intent Broadcasting Messages to Other Components

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Intents can be used to broadcast messages to other components of your application (such as a running background service) or to the entire Android system.

To send a broadcast within your application, use the LocalBroadcastManager class:

Intent intent = new Intent("com.example.YOUR_ACTION"); // the intent action
intent.putExtra("key", "value"); // data to be passed with your broadcast

LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
manager.sendBroadcast(intent);

To send a broadcast to components outside of your application, use the sendBroadcast() method on a Context object.

Intent intent = new Intent("com.example.YOUR_ACTION"); // the intent action
intent.putExtra("key", "value"); // data to be passed with your broadcast

context.sendBroadcast(intent);

Information about receiving broadcasts can be found here: Broadcast Receiver



Got any Android Question?