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 int getIntProperty(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(DEFAULT_FILE_NAME, Context.MODE_PRIVATE);
    return sp.getInt(key, -1);
}

From source file:Main.java

public static String getUserPwd(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(USER_INFO, Context.MODE_PRIVATE);
    String userPwd = preferences.getString(USER_PWD, "");
    return userPwd;
}

From source file:Main.java

public static String readString(Context context, String key) {
    SharedPreferences pre = context.getSharedPreferences(STORE_NAME, Context.MODE_PRIVATE);
    return pre.getString(STORE_KEY_PREFIX + key, "");
}

From source file:Main.java

public static String getUserIcon(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(USER_INFO, Context.MODE_PRIVATE);
    String userIcon = preferences.getString(USER_ICON, "");
    return userIcon;
}

From source file:Main.java

public static int getInt(Context context, String title) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    return sp.getInt(title, 0);
}

From source file:Main.java

/**
 * Clears all messages.//from w w w.j av  a 2s . c o m
 * 
 * @param context The application context.
 * @return The number of messages cleared.
 */
public static int clearMessages(Context context) {
    SharedPreferences sp = context.getSharedPreferences("messages", Context.MODE_PRIVATE);
    int messages = sp.getInt("messages", 0);
    sp.edit().putInt("messages", 0).commit();
    return messages;
}

From source file:Main.java

public static void cachePullSen(Context context, float sen) {
    SharedPreferences sp = context.getSharedPreferences(CONFIG, Context.MODE_PRIVATE);
    sp.edit().putFloat(KEY_PS, sen).commit();
}

From source file:Main.java

public static boolean getBoolean(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);

    return sp.getBoolean(key, false);
}

From source file:Main.java

public static String getVersion(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(VERSION, Context.MODE_PRIVATE);
    String version = preferences.getString(VERSION_KEY, "1");
    return version;
}

From source file:Main.java

public static Long getLong(Context context, String title) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    return sp.getLong(title, 0);
}