Example usage for android.content Context getSharedPreferences

List of usage examples for android.content Context getSharedPreferences

Introduction

In this page you can find the example usage for android.content Context getSharedPreferences.

Prototype

public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);

Source Link

Document

Retrieve and hold the contents of the preferences file, returning a SharedPreferences through which you can retrieve and modify its values.

Usage

From source file:Main.java

public static void clear(Context context) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.clear();/* w  w  w.  j ava 2s.com*/
    editor.apply();
}

From source file:Main.java

public static String getRegistrationId(Context ctx) {
    SharedPreferences preferences = ctx.getSharedPreferences("PREFS", 0);
    return preferences.getString("registration_id", "no_registration_id_yet");
}

From source file:Main.java

public static void setGuided(Context context) {
    SharedPreferences pref = context.getSharedPreferences(context.getPackageName() + "_preferences", 0);
    pref.edit().putBoolean(IS_GUIDED, true).commit();
}

From source file:Main.java

public static void setWindowX(float x, Context context) {
    SharedPreferences sp = context.getSharedPreferences(PREFS_CACHE_ONE, 0);
    SharedPreferences.Editor editor = sp.edit();
    editor.putFloat("x", x);
    editor.commit();//from  w w w  .  j  a va 2s  .co m
}

From source file:Main.java

public static boolean isFirstRun(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
    return prefs.getBoolean(PREF_FIRST_RUN, true);
}

From source file:Main.java

public static void setEnableGprs(boolean isEnableGprs, Context context) {
    SharedPreferences sp = context.getSharedPreferences(PREFS_CACHE_ONE, 0);
    SharedPreferences.Editor editor = sp.edit();
    editor.putBoolean("isEnableGprs", isEnableGprs);
    editor.commit();/*w  ww .j av a  2 s .co m*/
}

From source file:Main.java

public static Map<String, ?> getAll(Context context) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    Map<String, ?> allKeyValue = sp.getAll();
    return allKeyValue;
}

From source file:Main.java

public static int getCountryToIdx(Context context) {
    SharedPreferences pref = context.getSharedPreferences(CURRENCY_PREF_NAME, 0);
    return pref.getInt(COUNTRY_TO_IDX, 0);
}

From source file:Main.java

public static boolean loadAutoRefreshFromPreference(Context c) {
    SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    return preferences.getBoolean(PREF_AUTO_REFRESH, true);
}

From source file:Main.java

public static void setLocaleIndexed(Context context, String locale) {
    context.getSharedPreferences(INDEX, 0).edit().putBoolean(locale, true).commit();
}