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

From source file:Main.java

public static void setCacheTime(Context context, long time) {
    SharedPreferences settings = context.getSharedPreferences("Preference", 0);
    settings.edit().putLong("CacheTime", time).commit();
}

From source file:Main.java

public static void cacheFapisLoginUser(String token, Context context) {
    SharedPreferences sharedPreferences = context.getSharedPreferences("configuration", 0);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString("token", token);
    editor.commit();/*from   w w w .j  ava  2  s.c  o m*/
}

From source file:Main.java

public static void saveColor(Context context, int color) {
    SharedPreferences settings = context.getSharedPreferences(PREFERENCES, 0);
    settings.edit().putInt(COLOR, color).commit();
}

From source file:Main.java

public static void logout(Context context) {
    SharedPreferences preferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.clear();/*from w  ww.  ja  va  2  s  .com*/
    editor.commit();
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancelAll();
}

From source file:Main.java

public static int getInt(Context context, String key) {
    SharedPreferences shared = context.getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
    int value = shared.getInt(key, 0);
    return value;
}

From source file:Main.java

public static void setDeskEffect(Context context, int tap) {
    SharedPreferences preferences = context.getSharedPreferences("DeskEffect", Context.MODE_PRIVATE);
    preferences.edit().putInt("DeskEffectItem", tap).commit();
}

From source file:Main.java

public static long getLong(Context context, String key) {
    SharedPreferences shared = context.getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
    long value = shared.getLong(key, 0L);
    return value;
}

From source file:Main.java

public static void saveLogin(Context context) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(SHERED_NAME, Context.MODE_PRIVATE);
    sharedPreferences.edit().putBoolean(SHARED_KEY_IS_LOGGED, true).commit();

}

From source file:Main.java

public static void setDesktopScreens(Context context, int screens) {
    SharedPreferences sp = context.getSharedPreferences(ALMOSTNEXUS_PREFERENCES, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.putInt("desktopScreens", screens - 1);
    editor.commit();//from   ww  w  .  j a v  a  2s . c  om
}