Created
October 14, 2022 16:22
-
-
Save parthdesai1208/01dccd5801e5ccdad23431cf37ceca07 to your computer and use it in GitHub Desktop.
shared preferences using kotlin delegation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val sharedApplicationContext: Context get() = sharedApplicationContextBackingProperty | |
?: throw IllegalStateException( | |
"Application context not initialized yet." | |
) | |
private var sharedApplicationContextBackingProperty: Context? = null | |
class App : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
sharedApplicationContextBackingProperty = applicationContext | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for get() | |
val count = DefaultSharedPrefs.clickCount | |
for set() | |
DefaultSharedPrefs.clickCount++ | |
or | |
DefaultSharedPrefs.clickCount = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment