get String Preferences - Android android.content

Android examples for android.content:SharedPreferences

Description

get String Preferences

Demo Code

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class Main {

  public static Map<String, String> getStringPreferences(Context context, String... prefNames) {
    SharedPreferences preferences = getDefaultPreference(context);
    Map<String, String> prefMap = new HashMap<String, String>();
    for (String name : prefNames) {
      prefMap.put(name, preferences.getString(name, ""));
    }/*  w  ww . j a va 2s.c om*/
    return prefMap;
  }

  public static SharedPreferences getDefaultPreference(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context);
  }

}

Related Tutorials