Created
June 9, 2020 22:52
-
-
Save shafty023/7f92ff5f3275dd606ab8c7eb7a442512 to your computer and use it in GitHub Desktop.
Persist the db key to storage
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
/** | |
* Save the storable instance to preferences. | |
* | |
* @param storable a storable instance | |
*/ | |
fun saveToPrefs(context: Context, storable: Storable) { | |
val serialized = Gson().toJson(storable) | |
val prefs = context.getSharedPreferences("database", | |
Context.MODE_PRIVATE) | |
prefs.edit().putString("key", serialized).apply() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment