Skip to content

Instantly share code, notes, and snippets.

@DjangoLC
Created June 4, 2020 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DjangoLC/ce6827e3a47fbc1d46bc016b0369f36b to your computer and use it in GitHub Desktop.
Save DjangoLC/ce6827e3a47fbc1d46bc016b0369f36b to your computer and use it in GitHub Desktop.
class UserPreferences(context: Context) {
companion object {
const val USER_PREFERENCES = "USER_PREFERENCES"
const val USER_TOKEN = "USER_TOKEN"
}
private val preferences = context.applicationContext
.getSharedPreferences(USER_PREFERENCES, Context.MODE_PRIVATE)
fun getString(key: String): String? {
return preferences.getString(key, "")
}
fun save(key: String, value: String) {
with(preferences) {
edit {
putString(key, value)
commit()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment