get Shared Preference String - Android android.content

Android examples for android.content:SharedPreferences

Description

get Shared Preference String

Demo Code

import android.content.Context;
import android.content.SharedPreferences;

public class Main {

  public static final String PREFS_NAME = "_java2s.com";

  public static String getSharedPreferenceString(Context c, String preference) {
    SharedPreferences settings = c.getSharedPreferences(PREFS_NAME, 0);
    return settings.getString(preference, "");
  }// ww  w . j a  v  a  2s. c  o  m

  public static String getSharedPreferenceString(Context c, String preference, String defaultValue) {
    SharedPreferences settings = c.getSharedPreferences(PREFS_NAME, 0);
    return settings.getString(preference, defaultValue);
  }

}

Related Tutorials