Example usage for android.content Context MODE_PRIVATE

List of usage examples for android.content Context MODE_PRIVATE

Introduction

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

Prototype

int MODE_PRIVATE

To view the source code for android.content Context MODE_PRIVATE.

Click Source Link

Document

File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).

Usage

From source file:Main.java

public static void setSessionField(Activity activity, String field, String value) {
    SharedPreferences sharedPref = activity.getSharedPreferences("Session", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putString(field, value);/*  w ww  .  j a v  a 2s.com*/
    editor.commit();
}

From source file:Main.java

public static boolean getBoolean(Context ctx, String key, boolean defaultValue) {
    SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    return sp.getBoolean(key, defaultValue);
}

From source file:Main.java

public static int getChangeMode(Context ctx) {
    SharedPreferences sp = ctx.getSharedPreferences("config_mode", Context.MODE_PRIVATE);
    return sp.getInt(Mode, MODE_DAY);
}

From source file:Main.java

public static String getString(Context ctx, String key, String defaultValue) {
    SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    return sp.getString(key, defaultValue);
}

From source file:Main.java

public static void putInt(Context context, String title, int content) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor edit = sp.edit();
    edit.putInt(title, content);//from   w ww . j  a  va2 s. c  o  m
    edit.commit();
}

From source file:Main.java

public static void putBoolean(Context context, String key, boolean value) {
    if (sp == null) {
        sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    }//from w  w  w  .  j ava  2s . co  m
    sp.edit().putBoolean(key, value).commit();
}

From source file:Main.java

public static String getStringFromSharePrefs(Context context, String fileName, String key,
        String defaultValue) {//from www . j av  a2s .  com
    SharedPreferences preferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    return preferences.getString(key, defaultValue);
}

From source file:Main.java

public static void saveMac(Context context, String mac) {

    SharedPreferences sharedPreferences = context.getSharedPreferences(MAC_ADDRESS, Context.MODE_PRIVATE);
    sharedPreferences.edit().putString(MAC_ADDRESS, mac).commit();
}

From source file:Main.java

public static void saveMutesState(String muteState, Context mContext) {
    if (mContext != null) {
        SharedPreferences preferences = mContext.getSharedPreferences("mute_setting", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();

        editor.putString("UPDATE_MUTE", muteState);
        editor.commit();//w  w  w  .  ja va  2  s.c o  m
    }
}

From source file:Main.java

public static void putLong(Context context, String title, long content) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor edit = sp.edit();
    edit.putLong(title, content);/*ww w . ja v  a2  s . c  o  m*/
    edit.commit();
}