rx-shared-preferences icon indicating copy to clipboard operation
rx-shared-preferences copied to clipboard

observing preferences does not work after GC

Open piotrbazan opened this issue 9 years ago • 1 comments

BasePreference<T> class registers listener:

mSharedPreferences.registerOnSharedPreferenceChangeListener((preferences, key) -> mSubject.onNext(key));

but according to the SharedPreferences doc:

  • Caution: The preference manager does not currently store a strong reference to the listener. You must store a strong reference to the listener, or it will be susceptible to garbage collection. We recommend you keep a reference to the listener in the instance data of an object that will exist as long as you need the listener.

This is confirmed in the runtime. A few first preference changes make actions trigger but after GC there are no actions invoked.

piotrbazan avatar Jan 07 '16 20:01 piotrbazan

Nice find. Thanks for your comment. I will look into it. Perhaps, I should use static or change the design a little bit.

henrytao-me avatar Jan 08 '16 00:01 henrytao-me