ursus
08/14/2020, 3:56 AMstreetsofboston
08/14/2020, 4:22 AMapply
. When using commit
it probably will be slower.
When calling apply
, it applies it first to memory only and then immediately kicks of a background task to properly commit it to local persistent storage.gildor
08/14/2020, 4:51 AMdoes it mean its not as durable as a sqlite wouldIt’s definitely not as durable as sqlite
ursus
08/14/2020, 8:37 PMstreetsofboston
08/14/2020, 8:40 PMursus
08/14/2020, 8:41 PMstreetsofboston
08/14/2020, 8:41 PMursus
08/14/2020, 8:43 PMstreetsofboston
08/14/2020, 8:44 PMursus
08/14/2020, 8:45 PMstreetsofboston
08/14/2020, 8:46 PMursus
08/14/2020, 8:47 PMstreetsofboston
08/14/2020, 8:49 PMursus
08/14/2020, 8:50 PMstreetsofboston
08/14/2020, 8:51 PMursus
08/14/2020, 8:53 PMstreetsofboston
08/14/2020, 8:55 PMursus
08/14/2020, 9:03 PMstreetsofboston
08/14/2020, 9:07 PMsharedPrefs.edit()
.putString(USER, user.toJsonString())
.putString(PROFILE, userProfile.toJsonString())
...
.apply()
Then either the entire change between edit()
and apply()
will get committed or not (veeeeeery small chance it’d fail)ursus
08/14/2020, 9:08 PMstreetsofboston
08/14/2020, 9:09 PMursus
08/14/2020, 9:10 PMSettingsDao.saveSettings(settings: Settings) {
prefs.edit().putString("settings", settings.toJson()
}
ProfileDao.saveProfile(profile: Profile) {
prefs.edit().putString("profile", profile.toJson()
}
-....
fun sync() {
settingsDao.saveSettings(settings)
profileDao.saveProfile(profile)
}
streetsofboston
08/14/2020, 9:12 PMursus
08/14/2020, 9:14 PMstreetsofboston
08/14/2020, 9:14 PMputString
or an apply
call to the SharedPreference’s Editor can happen… but it is not worth fretting over.ursus
08/14/2020, 9:16 PMstreetsofboston
08/14/2020, 9:18 PMursus
08/14/2020, 9:19 PMstreetsofboston
08/14/2020, 9:21 PMEditor
object.ursus
08/14/2020, 9:23 PMstreetsofboston
08/14/2020, 9:26 PMursus
08/14/2020, 9:28 PMstreetsofboston
08/14/2020, 9:29 PMursus
08/14/2020, 9:30 PMstreetsofboston
08/14/2020, 9:32 PMEditor
and have them make modifications to that editor. Then your app calls those methods for each module with an Editor
and after all these calls are done, call apply
on it.ursus
08/14/2020, 9:33 PMstreetsofboston
08/14/2020, 9:33 PMEditor
that is passed.editor1.apply()
and then editor2.apply()
a little later… what is the chance of a crash happening when those two are called. What are the situations where that could happen and their likelyhood.ursus
08/14/2020, 9:38 PMstreetsofboston
08/14/2020, 9:42 PMapply
for some reason throws an exception, your app is in bigger trouble already.ursus
08/14/2020, 9:48 PM