How to create and use a Singleton in Kotlin

Oscar de la Hera Gomez
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.

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.
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