rx-shared-preferences
rx-shared-preferences copied to clipboard
observing preferences does not work after GC
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.
Nice find. Thanks for your comment. I will look into it. Perhaps, I should use static or change the design a little bit.