Skip to content

Instantly share code, notes, and snippets.

@geftimov
Created November 13, 2014 12:29
Show Gist options
  • Save geftimov/0b2584115df806b9a12f to your computer and use it in GitHub Desktop.
Save geftimov/0b2584115df806b9a12f to your computer and use it in GitHub Desktop.
SharedPrefs config
import android.content.Context;
import android.content.SharedPreferences;
import java.util.HashSet;
import java.util.Set;
public class SharedPrefs {
private static SharedPrefs singelton;
private final SharedPreferences sharedPreferences;
private static final String SHARED_PREFERENCES_NAME = "jira_shared_prefs";
//saved keys
private static final String SESSION_ID_KEY = "session_id_key";
public static SharedPrefs with(final Context context) {
if (singelton == null) {
synchronized (SharedPrefs.class) {
if (singelton == null) {
singelton = new SharedPrefs(context);
}
}
}
return singelton;
}
private SharedPrefs(final Context context) {
if (context == null) {
throw new IllegalArgumentException("Context must not be null.");
}
sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
}
public void saveSessionId(final String sessionId) {
final android.content.SharedPreferences.Editor edit = sharedPreferences.edit();
edit.putString(SESSION_ID_KEY, sessionId);
edit.commit();
}
public void deleteSessionId() {
final android.content.SharedPreferences.Editor edit = sharedPreferences.edit();
edit.remove(SESSION_ID_KEY);
edit.commit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment