How to create and use a Singleton in Kotlin

A guide for creating and using Singletons in an Android app written in Kotlin.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 06/13/2023 at 13:26
Last Updated on 06/13/2023 at 13:59
Three flowers that represent Kotlin, Android and Android Studio. Beneath it sits the text "Singleton."

A guide for creating and using Singletons in an Android app written in Kotlin.

SubscribeDownload Open Source Kotlin Starter Project

How to create a Singleton

A screenshot of Android Studio showing how to create a Singleton. The code demonstrated is below.

Create a new file named after the Singleton and implement code similar to that below.

We suggest placing it in a folder called Coordinators or Managers.

How to use a Singleton

A screenshot of Android Studio showing how to invoke a Singleton function. The code is available below.

To use a singleton variable, use a line similar to:

SampleCoordinator.shared.variableName
To run a function of a Singleton, use a line similar to:
SampleCoordinator.shared.function()

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