russhwolf / multiplatform-settings

A Kotlin Multiplatform library for saving simple key-value data
Apache License 2.0
1.69k stars 67 forks source link

Add option to use commit() instead of apply() on Android #60

Closed russhwolf closed 4 years ago

russhwolf commented 4 years ago

The Android SharedPreferences interface has two methods to commit changes when editing. apply() is the recommended default and is what AndroidSettings does currently, but some users might prefer the synchronous commit() instead. I'd like to verify that there is demand for this, and if so add a configuration option to use commit() instead. Probably this is a constructor argument, but other suggestions are welcome.

vanniktech commented 4 years ago

I'm fine with apply() no need for commit

anuragdalia commented 4 years ago

how about something like a simple commit(async = true)

russhwolf commented 4 years ago

Currently there's no common editor abstraction since Android is the only platform for which that exists. So there's nowhere to put a call like commit(async = true).

dzolnai commented 4 years ago

This is a feature we would like to have, we use the Settings object to set the environment in our apps, and then immediately restart the app using ProcessPhoenix. Because apply() is used, and the process is killed, the changes are not saved.

russhwolf commented 4 years ago

Thanks for confirming a use-case. I'll merge the PR and look at doing a release this weekend.

russhwolf commented 4 years ago

Published 0.6.3 including this update