How to listen for an intent using a Broadcast Receiver in a Composable

Oscar de la Hera Gomez
Three flowers that represent Kotlin, Android and Android Studio side by side. Beneath them sits the text “Receive Broadcasts in Composables.”

A step by step guide on listening for an intent, that may or may not have extras, using a Broadcast Receiver in a Composable in Kotlin and Android Studio.

This post is a part of a mini series on sending and receiving functional intents in an Android app. The rest of the tutorials are available at the end.

Please note that we have chosen to use the term "Notifications" to standardize naming conventions across iOS and Android. If you wish to exchange Notifications for Intents, we welcome you too.

Step One: Setup the Notifications Coordinator

A screenshot of Android Studio showing the NotificationCoordinator.kt file. Code available below.

For intents to be registered across an app it must be sent from a central manager, which we call a NotificationsCoordinator.

Step Two: Broadcast the Intent

A screenshot of Android Studio showing the MainActivity sending an Intent that we declared in this tutorial in the onResume function.

Follow the tutorial below to learn how to structure a project to manage and broadcast intents.

Step Three: Add Disposable Receiver to Composable

A screenshot of Android Studio showing the sample Composable  with a disposable effect that incorporates a broadcast receiver.

Add and customize your Broadcast Receiver using the sample code below.

Composable's need to use a disposable effect so that the Broadcast Receiver is disposed of when the Composable is removed.

To learn more above why we used RECIEVER_NOT_EXPORTED, consult the post below.

Step Four: Add the Composable to the UI

A screenshot of Android Studio showing us adding the composable to the UI.

If you have not already, add the Composable to the app.

Step Five: Test

A screenshot of Android Studio showing the logs confirming that the composable received the broadcast.

Run the app and verify that the notification is received.

Looking to learn more about Intents in Android ?

Consult the tutorials linked below to learn more about sending and receiving Intents in Android and Kotlin.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details