Skip to content

Instantly share code, notes, and snippets.

@dzwillpower
Forked from tediscript/AndroidSettings.java
Created July 10, 2013 06:35
Show Gist options
  • Save dzwillpower/5963901 to your computer and use it in GitHub Desktop.
Save dzwillpower/5963901 to your computer and use it in GitHub Desktop.
#SharedPreferences SharedPreferences 设置
package com.tediscript.android;
import android.content.Context;
import android.content.SharedPreferences;
public class Settings {
public static String PREFS_NAME = "com.tediscript.android.settings";
public static void putString(Context ctx, String key, String value) {
SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString(key, value);
editor.commit();
}
public static String getString(Context ctx, String key, String defaultValue) {
SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, 0);
return settings.getString(key, defaultValue);
}
public static void putInt(Context ctx, String key, int value) {
SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt(key, value);
editor.commit();
}
public static int getInt(Context ctx, String key, int defaultValue) {
SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, 0);
return settings.getInt(key, defaultValue);
}
public static void putBoolean(Context ctx, String key, boolean value) {
SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(key, value);
editor.commit();
}
public static boolean getBoolean(Context ctx, String key,
boolean defaultValue) {
SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, 0);
return settings.getBoolean(key, defaultValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment