Code example for SharedPreferences

Methods: getAllgetStringSet

-1
  @TargetApi(11) 
  @Override 
  public void onSharedPreferenceChanged(SharedPreferences prefs,
                                        String key) {
    Intent i=new Intent(ACTION_SYNC_PREF);
    Object value=prefs.getAll().get(key);
 
    i.putExtra(EXTRA_SENDER, getPackageName());
    i.putExtra(EXTRA_KEY, key);
 
    if (value instanceof Boolean) {
      i.putExtra(EXTRA_VALUE, (Boolean)value);
      i.putExtra(EXTRA_TYPE, TYPE_BOOLEAN);
    } 
    else if (value instanceof Float) {
      i.putExtra(EXTRA_VALUE, (Float)value);
      i.putExtra(EXTRA_TYPE, TYPE_FLOAT);
    } 
    else if (value instanceof Integer) {
      i.putExtra(EXTRA_VALUE, (Integer)value);
      i.putExtra(EXTRA_TYPE, TYPE_INT);
    } 
    else if (value instanceof Long) {
      i.putExtra(EXTRA_VALUE, (Long)value);
      i.putExtra(EXTRA_TYPE, TYPE_LONG);
    } 
    else if (value instanceof String) {
      i.putExtra(EXTRA_VALUE, (String)value);
      i.putExtra(EXTRA_TYPE, TYPE_STRING);
    } 
    else if (value instanceof Set<?>
        && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      i.putExtra(EXTRA_VALUE,
                 prefs.getStringSet(key, null).toArray(new String[0]));
      i.putExtra(EXTRA_TYPE, TYPE_STRINGSET);
    } 
 
    sendBroadcast(i, PERM_SYNC_PREF);
  }