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 String getString(Context context, String title) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    return sp.getString(title, "");
}

From source file:Main.java

public static String getStringPrefs(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(PRE_NAME, Context.MODE_PRIVATE);
    return sp.getString(key, "");

}

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);// www  . j av  a 2s.  c o  m
    editor.commit();
}

From source file:Main.java

public static void setString(Context ctx, String key, String value) {
    SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    sp.edit().clear();//from   w  w  w. j a  va 2s  .c o  m
    sp.edit().putString(key, value).commit();
}

From source file:Main.java

public static void putString(Context context, String key, String value) {
    SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    sp.edit().putString(key, value).commit();
}

From source file:Main.java

public static void saveConfigServidor(String login, String senha, String url, Context context) {

    SharedPreferences.Editor editor = context.getSharedPreferences("RestService", Context.MODE_PRIVATE).edit();
    editor.putString("login", login);
    editor.putString("senha", senha);
    editor.putString("url", url);
    editor.commit();// ww  w  .  j  a  va2 s .c o m
}

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

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  w  w.ja v  a 2 s.c  o  m
    //        SharedPreferencesCompat.apply(editor);
    editor.commit();
}

From source file:Main.java

public static void clearSharePrefrences(Context context) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.clear();/*from w  w w.  ja  v  a 2 s  .com*/
    editor.commit();
}

From source file:Main.java

public static void setBoolean(Context ctx, String key, boolean value) {
    SharedPreferences spf = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    spf.edit().putBoolean(key, value).commit();
}