I am trying to convert an Android app from Java to Kotlin. There are a few singletons in the app. I used a companion object for the singletons without constructor parameters
If the only parameter you need is the application Context
, then you can initialize it to a top level val
, early in a ContentProvider
, like the Firebase SDK does.
Since declaring a ContentProvider
is a bit cumbersome, I made a library that provides a top level property named appCtx for all places where you don't need an Activity or other special lifecycle bound context.