Android development can be (and usually is) much easier and satisfying with Kotlin, compared to Java. But it’s also quite different. Lots of things, like predefined nullability (or lack of it), no static as we know it, extension and top-level functions are there to be used in our favor. No wonder that it may be confusing what approach to choose, especially when the same thing can be done in different ways.
Today I’m gonna present you a better way of initializing and using SharedPreferences in your Kotlin app. No more repeating code with initialization in every place you want to get a preference, no more long lines to get or set a pref. How to accomplish this? Use object with lateinit and custom getters & setters.