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 setBoolean(Context ctx, String key, boolean value) {
    SharedPreferences sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE);
    sp.edit().putBoolean(key, value).commit();
}

From source file:Main.java

public static void deleteLogin(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(USER_INFO, Context.MODE_PRIVATE);
    preferences.edit().clear().commit();
    SharedPreferences preferences1 = context.getSharedPreferences(USER_INFO_OTHER, Context.MODE_PRIVATE);
    preferences1.edit().clear().commit();
    SharedPreferences preferences2 = context.getSharedPreferences(QQ, Context.MODE_PRIVATE);
    preferences.edit().clear().commit();
}

From source file:Main.java

public static SharedPreferences getFiredAlertsTable(Context context) {
    return context.getSharedPreferences(ALERTS_SHARED_PREFS_NAME, Context.MODE_PRIVATE);
}

From source file:Main.java

public static void setPlaymode(Context context, String key, int value) {
    SharedPreferences sp = context.getSharedPreferences("atguigu", Context.MODE_PRIVATE);
    sp.edit().putInt(key, value).commit();
}

From source file:Main.java

public static void setLong(Context context, String key, long value) {
    SharedPreferences sp = context.getSharedPreferences("configdata", Context.MODE_PRIVATE);
    sp.edit().putLong(key, value).commit();
}

From source file:Main.java

public static void setIsRunning(Context context, boolean isRunning) {
    SharedPreferences sp = context.getSharedPreferences(EXT_CONFIG, Context.MODE_PRIVATE);
    sp.edit().putBoolean(KEY_IS_RUNNING, isRunning).commit();
}

From source file:Main.java

static void saveLastPhoneCount(Context context, int count) {
    SharedPreferences prefs = context.getSharedPreferences(AGE_PREFERENCES, Context.MODE_PRIVATE);
    Editor editor = prefs.edit();//  w w  w  .  ja v a  2s  . co  m
    editor.putInt(AGE_LAST_PHONE_COUNT, count);
    editor.commit();
}

From source file:Main.java

public static void setPosterHelpStatus(Context context, boolean status) {
    SharedPreferences sp = context.getSharedPreferences("poster_help", Activity.MODE_PRIVATE);
    SharedPreferences.Editor tor = sp.edit();
    tor.putBoolean("poster_help", status);
    tor.commit();//from   w  w w  . j av  a  2  s . c  o m
}

From source file:Main.java

public static void saveSharedPreString(Context context, String key, String value) {
    settings = context.getSharedPreferences(XML_Settings, Context.MODE_PRIVATE);
    settings.edit().putString(key, value).commit();
}

From source file:Main.java

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