Reputation: 3946
I know this issue has been discussed already (here for example), but It's still unclear to me whether it is, or not, safe to have a Preference activity that updates the SharedPreferences and background threads that read from it simultaneously ?
In my specific example, I have a PreferenceActivity and PreferenceFragments that the user interacts with to change the preferences, and a background Service that read and acts upon those prefs.
I don't want to leave it to luck, just want to make sure if I should be locking the SharedPreference object each time I read from it (because writing to it is done automatically through the PreferencesActivity).
Thanks!
Upvotes: 2
Views: 1855
Reputation: 1828
As discussed in the post you linked. Unless you specifically tells Android in you manifest to run your service in another process it should be safe to write and read at the same time.
So it would probably be fine your case.
Upvotes: 2