I've been looking into Android development using Kotlin and I ran into a situation. I'm trying to figure out how to create a singleton using the recommended Kotlin "object" and pass it an Android Context, more specifically the context from the Context.getApplicationContext() method.
It's essentially the same question as here, but since Kotlin was in beta until just a few days ago, I was wondering if the answer might have changed for V1.0.0.
I'd rather not use the accepted answer in the referred question (use a setter to set the context) because it would mean I'd have to (re)set the context to make sure it's not null before using the singleton. Not a big deal, but it feels like there should be a better way. It might also raise issues when setting the context from different threads at the same time...? Or maybe not, since the Context would always be the same Application Context.
Using an injection library as suggested in the other answer to that question would work, but I'm looking for a more "idiomatic" way of doing this since I'm trying to learn the language.
Anyone know another way?
Thanks!