I have a simple activity consisting of a main activity, a second activity and a preferenceactivity.
What I do:
- I run the app, mainactivity triggers oncreate
- Oncreate fetches sharedpreferences and prints the value to the console
- I go to the settings, change the value of the amount and press back.
- oncreate triggers again and logs the newly set value (good)
- The oncreate also triggers a repeating alarm. In my receiver class I also log the sharedpreferences.
- The problem: the value logged in my receiving class is still the old value!
- Next I completely close the app. The alarm keeps running (as it should) and now the receiver starts logging the new, correct value.
So, change preference value is immediately picked up in main activity Other classes requires the app to exit / restart to pickup the change.
I've been reading the google documentation about preferences, followed tutorials, ... been struggling with this for 3 evenings.
Advice would be appreciated.
EDIT: found what was the problem, had this in my manifest
<receiver android:name="Alarm" android:process=":remote" />
Because it was on another process the preference changes were not detected
Found it thanks to this post: https://stackoverflow.com/a/10770175/1323883