I would like a clean way to check whether a preference changed. This check should be done when the preferenceActivity finishes.
My current thought is to store the values of interest at onCreate using names like oldInterval and comparing them to the value at the time of onDestroy. I would have to specify this for every preference of interest however. Rather, I would like to store a backup of the whole SharedPreferences object at onCreate, so I can query it at onDestroy. Hope my question is clear and you can help.
There are two options –
SharedPreferences.getAll()will return aMapof all values in the SharedPreferences object. You can use that to compare before-and-after.Possibly a better option is to use
SharedPreferences.registerOnSharedPreferenceChangeListener(), which will set up a listener which is called whenever one of your shared preferences is changed. They you can just set a boolean and you’ll know immediately.This is all documented at the SharedPreferences Javadoc page