In one of my onTouch() listeners, I currently check for boolean user setting before deciding how to handle the touch event:
boolean shouldCue = preferences.getBoolean(v.getContext().getString(R.string.should_cue), true);
Observing LogCat, I can see that when the user touches the screen, this statement is called numerous times!
So, I was thinking of "caching" that shouldCue
boolean by implementing an onSharedPreferenceChanged() listener.
I could of course go ahead and implement this and... observe negligible difference on my super-fast Android device. I can't possibly test this on "the majority of Android devices" out there because there are way too many variations.
So my questions are:
- Would onSharedPreferenceChanged() be called even if the preference wasn't changed via UI? (i.e. programmatically via
editor.commit();
) - Provided that SharedPreferences boolean can be modified from either UI or programmatically (but not both simultaneously), would caching it mandate @Synchronized handling?
- Any estimates regarding the performance difference between the cached vs. non-cached method? (to simplify the question, let's assume we are referring to an old phone like the Droid 1 A855)