How to create an Android Notification Coordinator in Kotlin

A step by step guide on creating a manager that can send intents from any activity or composable which can be received across an Android app.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 06/15/2023 at 11:08
Last Updated on 06/16/2023 at 10:58
Three flowers that represent Kotlin, Android and Android Studio side by side. Beneath them sits the text “Notification Coordinator.”

A step by step guide on creating a manager that can send intents from any activity or composable which can be received across an Android app.

SubscribeDownload Open Source Kotlin Starter Project

This post is the first 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 to.

Step One: Create the Package

A screenshot of Android Studio showing how to create a package. Selected is the Coordinators package and highlighted is New > Package within the pop up that appears when you right click.

In the project, create a package called notificationCoordinator.

We recommend that you place it under coordinators.

A screenshot of Android Studio showing us naming the package notificationCoordinator.

Step Two: Create declaration file

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

In the package created in Step One, create a new Kotlin file called NotificationCoordinator.kt and paste in the code below.

How to create and use a Singleton in Kotlin

Step Three: Create the Internal Intents Extension

A screenshot of Android Studio showing an empty NotificationsCoordinator+InternalIntents.kt file.

In the package created in Step One, create a new Kotlin file called NotificationCoordinator+InternalIntents.kt and leave it blank for now.

This is where you will add functionality to standardize how you send intents within your application that are only available to your application.

How to broadcast an Intent in Kotlin

Step Four: Create the External Intents Extension

A screenshot of Android Studio showing an empty NotificationsCoordinator+ExternalIntents.kt file.

In the package created in Step One, create a new Kotlin file called NotificationCoordinator+ExternalIntents.kt and leave it blank for now.

This is where you will add functionality to standardize how you send intents within your application that are available outside of your application.

How to broadcast an Intent in Kotlin

Step Five: Initialize

A screenshot of Android Studio showing the MainActivity.kt file, initializing the NotificationCoordinator.

The coordinator requires the base context to be able to provide receivable notifications to an app.

Initialize the NotificationCoordinator in your MainActivity.kt using the function below.

We recommend that you do this in a function called setupCoordinators() which is initialized onCreate.

NotificationCoordinator.shared.initialize(context = baseContext)

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.

How to broadcast an Intent in KotlinHow to listen for an intent using a Broadcast Receiver in an ActivityHow to listen for an intent using a Broadcast Receiver in a Composable

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.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe