Skip to content

Instantly share code, notes, and snippets.

@shafty023
Created June 9, 2020 22:52
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 shafty023/7f92ff5f3275dd606ab8c7eb7a442512 to your computer and use it in GitHub Desktop.
Save shafty023/7f92ff5f3275dd606ab8c7eb7a442512 to your computer and use it in GitHub Desktop.
Persist the db key to storage
/**
* 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