Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
1) Make a new application
2) Make a new inner class or anonymous inner class to implement your OnSharedPreferenceChangeListener interface, since you don't want this to be part of the public interface of your object. lets calle this "MyListener"
3) Register MyListener like this;
getSharedPreferences(arg). registerOnSharedPreferenceChangeListener(new MyListener())
Expected: MyListener onSharedPreferenceChanged() should be invoked when preferences change
Actual: that may not happen
Since SharedPreferencesImpl stores the listener reference in a weak hash map, it will be collected at next GC time.
This is surprising to the caller, and it should be clearly documented that registerOnSharedPreferenceChangeListener() stores its listeners in a weak hash map and that the caller must retain references for the listener's expected lifetime.