Code example for Map

Methods: containsKey, put, remove

0
        SharedPreferences prefs = getSharedPreferences(branch);
        boolean enable = message.getBoolean("enable");
 
        // mListeners is only modified in this one observer, which is called 
        // from Gecko serially. 
        if (enable && !this.mListeners.containsKey(branch)) {
            SharedPreferences.OnSharedPreferenceChangeListener listener = new ChangeListener(branch);
            this.mListeners.put(branch, listener);
            prefs.registerOnSharedPreferenceChangeListener(listener);
        } 
        if (!enable && this.mListeners.containsKey(branch)) {
            SharedPreferences.OnSharedPreferenceChangeListener listener = this.mListeners.remove(branch);
            prefs.unregisterOnSharedPreferenceChangeListener(listener);
        } 
    } 
 
    @Override 
    public void handleMessage(String event, JSONObject message) {
        // Everything here is synchronous and serial, so we need not worry about 
        // overwriting an in-progress response. 
        mResponse = null;