Communicate two activities through custom Broadcast receiver

suggest change

You can communicate two activities so that Activity A can be notified of an event happening in Activity B.

Activity A

final String eventName = "";

protected void onCreate(Bundle savedInstanceState) {

protected void onDestroy() {

private void registerEventReceiver() {
    IntentFilter eventFilter = new IntentFilter();
    registerReceiver(eventReceiver, eventFilter);

private BroadcastReceiver eventReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
         //This code will be executed when the broadcast in activity B is launched

Activity B

final String eventName = "";

private void launchEvent() {
    Intent eventIntent = new Intent(eventName);

Of course you can add more information to the broadcast adding extras to the Intent that is passed between the activities. Not added to keep the example as simple as possible.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents