java - Android 5.0 SharedPreference.OnSharedPreferencesChangeListener not being called? Possibly a bug? -


i believe have found bug in android sdk

my onsharedpreferenceschangelistener not being called on change.

this not garbage collected listener - listener held in class instance variable. have been snooping around debugger. found notifylisteners method of editor class inside sharedpreferenceimpl, had 'mcr.keysmodified' size set '0' , instantly returned without notifying listener. have look:

a terrible android bug?

i found initialization of mmodified hashmap inside sharedpreferences editor class had error - highlighted red in intellij (their alot of errors showing in intellij). don't believe android developers leave soo many errors? intellij trying intelligent.

but code still not work.

here code i've created, using api. forgive me, code not finished:

public class settingsactivity extends activity {  private final static string pref_key_restart_required = "pref_requires_restart";  private sharedpreferences.onsharedpreferencechangelistener sharedpreferencechangelistener         = new sharedpreferences.onsharedpreferencechangelistener() {      @override     public void onsharedpreferencechanged(sharedpreferences sharedpreferences, string key) {         findviewbyid(r.id.settings_restart_alert).setvisibility(view.visible);     } };  @override protected void oncreate(bundle savedinstancestate) {      setuptheme();      super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_settings);      getfragmentmanager()             .begintransaction()             .replace(r.id.settings_fragment_container, new settingsfragment())             .commit();      getpreferences(mode_private).registeronsharedpreferencechangelistener(sharedpreferencechangelistener); }  public static class settingsfragment extends preferencefragment {      preference.onpreferencechangelistener onpreferencechangelistener = new preference.onpreferencechangelistener() {         @override         public boolean onpreferencechange(preference preference, object newvalue) {              resources res = getresources();              if (preference.getkey().equals(res.getstring(r.string.pref_key_enable_transparency))                     || preference.getkey().equals(res.getstring(r.string.pref_key_theme))) {                 sharedpreferences prefs = getactivity().getpreferences(mode_private);                 prefs.edit()                         .putboolean(pref_key_restart_required, true)                         .apply();             }              return true;         }     };      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          addpreferencesfromresource(r.xml.pref_general);          listpreference themelist = (listpreference)findpreference("pref_theme");         themelist.setonpreferencechangelistener(onpreferencechangelistener);          checkboxpreference transparencycheckbox = (checkboxpreference)findpreference("pref_transparency");         transparencycheckbox.setonpreferencechangelistener(onpreferencechangelistener);     }  } 

is i'm doing wrong? - intellij firing false negatives? or bug in android sdk?


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -