Code example for WeakHashMap

0
        } 
    } 
 
    private static final class ListenerWrapper implements 
            android.content.SharedPreferences.OnSharedPreferenceChangeListener {
        private static final Map<OnSharedPreferenceChangeListener, ListenerWrapper> INSTANCES = new WeakHashMap<OnSharedPreferenceChangeListener, ListenerWrapper>();
 
        public static synchronized ListenerWrapper obtain( 
                SharedPreferences prefs,
                OnSharedPreferenceChangeListener listener) {
            ListenerWrapper t = ListenerWrapper.INSTANCES.get(listener);
            if (t == null) {
                INSTANCES.put(listener, t = new ListenerWrapper(prefs, listener));
            } 
            return t;
        } 
 
        private OnSharedPreferenceChangeListener listener;
        private SharedPreferences prefs;
 
        private ListenerWrapper(SharedPreferences prefs,