Created
March 22, 2017 06:42
-
-
Save AkshayChordiya/6f01bd1ef1fdca8d8a7ff0c2ce7f2b5a to your computer and use it in GitHub Desktop.
Kotlin Article: PrefUtils.kt
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
fun getString(context: Context, key: String, defValue: String): String { | |
val pref = PreferenceManager.getDefaultSharedPreferences(context) | |
return pref.getString(key, defValue) | |
} | |
fun putString(context: Context, key: String, value: String) { | |
val pref = PreferenceManager.getDefaultSharedPreferences(context) | |
val editor = pref.edit() | |
editor.putString(key, value) | |
editor.apply() | |
} | |
fun getLong(context: Context, key: String, defValue: Long): Long { | |
val pref = PreferenceManager.getDefaultSharedPreferences(context) | |
return pref.getLong(key, defValue) | |
} | |
fun putLong(context: Context, key: String, value: Long) { | |
val pref = PreferenceManager.getDefaultSharedPreferences(context) | |
val editor = pref.edit() | |
editor.putLong(key, value) | |
editor.apply() | |
} | |
fun exists(context: Context, key: String): Boolean { | |
val pref = PreferenceManager.getDefaultSharedPreferences(context) | |
return pref.contains(key) | |
} | |
fun remove(context: Context, key: String) { | |
val pref = PreferenceManager.getDefaultSharedPreferences(context) | |
val editor = pref.edit() | |
editor.remove(key) | |
editor.apply() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment