I have a preference that controls whether or not my app plays a sound whenever the user clicks a button (which is done quite often, think of a calculator). Each time the user clicks the button the following method is called:
private void playButtonClickSound() {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(parentActivity);
boolean sounds = sharedPrefs.getBoolean("prefSounds", false);
if (sounds) {
// blah
}
}
I was thinking that reading preferences might be an expensive operation (similar to an I/O operation because preferences are persisted) and that since the user clicks buttons so often it might be a bad idea to do it this way.
In general is it a bad idea to read/write preferences frequently? If so, might there be another way such as registering a preference change listener to get notified when a preference changes?