Skip to content Skip to sidebar Skip to footer

Could Not Listen To Preference Changes?

class UserViewModel extends ViewModel{ appPrefs.registerOnSharedPreferenceChangeListener(preferenceChangeListener) }} private SharedPreferences.OnSharedPreferenceChangeListene

Solution 1:

I recommend to registerOnSharedPreferenceChangeListener() during fragment onResume() and unregisterOnSharedPreferenceChangeListener() at onPause() . Also check the preference key name what is observed. It could be a typo there.

`

publicvoidonSharedPreferenceChanged(SharedPreferences sharedPreferences,
            String key) {
            if (key.equals(KEY_PREF_SYNC_CONN)) {
                Preference connectionPref = findPreference(key);
                // Set summary to be the user-description for the selected value
                connectionPref.setSummary(sharedPreferences.getString(key, ""));
            }
        }

` Official documentation could be found here: https://developer.android.com/guide/topics/ui/settings.html#Fragment

Post a Comment for "Could Not Listen To Preference Changes?"