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 setDefaultScreen(Context context, int screens) {
    SharedPreferences sp = context.getSharedPreferences(ALMOSTNEXUS_PREFERENCES, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.putInt("defaultScreen", screens);
    editor.commit();//w w w  .j a  v  a 2  s.  c  om
}

From source file:Main.java

public static boolean checkFirstStart(Context paramContext) {
    SharedPreferences time = paramContext
            .getSharedPreferences("collection_agent_" + paramContext.getPackageName(), 0);
    int flag = time.getInt("flag", 0);
    if (flag == 0) {
        return true;
    }//from w w w  . java  2 s.c om
    return false;
}

From source file:Main.java

private static SharedPreferences getSharedPreferences(final Context context) {
    return context.getSharedPreferences(PREF_FILE_KEY, Context.MODE_PRIVATE);
}

From source file:Main.java

public static void setInt(Context ctx, String key, int value) {
    SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    sp.edit().putInt(key, value).apply();
}

From source file:Main.java

private static SharedPreferences getPreferencs(Context context) {
    if (mSp == null) {
        mSp = context.getSharedPreferences(CONFIG_SP, Context.MODE_PRIVATE);
    }//from  www. j  a  v a 2  s  .c om
    return mSp;
}

From source file:Main.java

public static void remove(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.remove(key);//from w ww.j  a va 2s.  c o  m
    //        SharedPreferencesCompat.apply(editor);
    editor.commit();
}

From source file:Main.java

public static void setCacheData(Context context, String data) {
    SharedPreferences settings = context.getSharedPreferences("Preference", 0);
    settings.edit().putString("CacheData", data).commit();
}

From source file:Main.java

public static void setInt(Context ctx, String key, int value) {
    SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    sp.edit().putInt(key, value).commit();
}

From source file:Main.java

public static void putValue(Context context, String value) {
    SharedPreferences spf = context.getSharedPreferences("md5", Context.MODE_PRIVATE);
    Editor edit = spf.edit();/*  www.  ja  v  a  2 s .  c  o  m*/
    edit.putString("sha", value);
    edit.commit();
}

From source file:Main.java

public static String get(Context context, String prefs) {
    SharedPreferences settings = context.getSharedPreferences("defaultPreferences", 0);
    return settings.getString(prefs, "");
}