Skip to content

Instantly share code, notes, and snippets.

@tediscript
Created April 26, 2013 12:35
Show Gist options
  • Save tediscript/5467107 to your computer and use it in GitHub Desktop.
Save tediscript/5467107 to your computer and use it in GitHub Desktop.
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);
}
}
Copy link

ghost commented Dec 31, 2013

Thank you this really helps out the development of my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment