Skip to content

Instantly share code, notes, and snippets.



Last active Jun 10, 2020
What would you like to do?
Messy preferences
class Preferences(context: Context) {
private val prefs: SharedPreferences = context.getSharedPreferences("Prefs", Context.MODE_PRIVATE)
companion object {
const val PREF_CURRENT_STATE = "CurrentState"
const val PREF_LAST_KNOWN_ERROR = "LastKnownError"
const val PREF_LAST_ACTION_PERFORMED = "LastActionPerformed"
fun getCurrentState() = prefs.getInt(PREF_CURRENT_STATE, 0)
fun setCurrentState(currentState: Int) {
prefs.edit().putInt(PREF_CURRENT_STATE, currentState).apply()
fun getLastKnownError() = prefs.getString(PREF_LAST_KNOWN_ERROR, "")
fun setLastKnownError(lastKnownError: String) {
prefs.edit().putString(PREF_LAST_KNOWN_ERROR, lastKnownError).apply()
fun getLastActionPerformed() = prefs.getString(PREF_LAST_ACTION_PERFORMED, "")
fun setLastActionPerformed(lastAction: String) {
prefs.edit().putString(PREF_LAST_ACTION_PERFORMED, lastAction).apply()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.