Hi all - I’m trying to use SharedPreferences in my...
# getting-started
w
Hi all - I’m trying to use SharedPreferences in my app in order to save a few preferences that then need to update pretty instantaneously inside the app. I have a settings page, where the user can switch from light to dark mode, and also update the voice of a TTS functionality. When the user ‘saves changes’ - I call editor.putXXXX(key, value).apply() for each setting and then close out of the settings page. Unfortuntately, I neither see the settings changed in my main activity, nor see the updated settings when I go back into the settings page. I understand that .apply() is asynchronous - I suspect that calling .apply() for each setting is going to cancel previous calls to .apply() - am I able to make several “puts” and then call .apply() just the once to make those several changes in one go? Why would I not see immediate changes in my main activity even if I call ‘sharedPrefs.getXXX’ again? I’m assuming it’s just an issue whereby the apply() function hasn’t actually finished yet? I’ve tried Googling and SOing for solutions but not getting anywhere
m
#android