Skip to content

Instantly share code, notes, and snippets.

@Mak-Sym
Created October 12, 2013 06:51
Show Gist options
  • Save Mak-Sym/6946663 to your computer and use it in GitHub Desktop.
Save Mak-Sym/6946663 to your computer and use it in GitHub Desktop.
@Override
protected void onPause() {
super.onPause();
// Unregister the listener whenever a key changes
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
protected void onResume() {
super.onResume();
//update phone preference summary with actual value
SharedPreferences preferences = getPreferenceScreen().getSharedPreferences();
phoneNumberPreference.setSummary(preferences.getString(PHONE_NUMBER_PREFERENCE, getResources().getString(R.string.phone_number_desc)));
preferences.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
//update phone preference summary with actual value
if(key.equals(PHONE_NUMBER_PREFERENCE)){
phoneNumberPreference.setSummary(preferences.getString(key, getResources().getString(R.string.phone_number_desc)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment