Best code examples for Android SharedPreferences class (android.content.SharedPreferences)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android SharedPreferences class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android SharedPreferences examples from Open Source projects
This code example shows how to use the following methods: edit
40:	return sharedPreferences.edit(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: contains, edit
39:	SharedPreferences.Editor editor = settings.edit(); 
-
41:	if (!settings.contains(PREF_UI_HIDESTATUSBAR)) 
-
43:	if (!settings.contains(PREF_UI_HIDEZOOMCONTROLS)) 
-
45:	if (!settings.contains(PREF_UI_SWAPMOUSEBUTTONS)) 
-
47:	if (!settings.contains(PREF_UI_INVERTSCROLLING)) 
-
49:	if (!settings.contains(PREF_UI_ASKONEXIT)) 
-
51:	if (!settings.contains(PREF_UI_AUTOSCROLLTOUCHPOINTER)) 
-
53:	if (!settings.contains(PREF_POWER_DISCONNECTTIMEOUT)) 
-
55:	if (!settings.contains(PREF_SECURITY_ACCEPTALLCERTIFICATES)) 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getLong, getString
122:	c2DMRegistrationId = prefs.getString("c2DMRegistrationId", null); 
123:	registeredUserId = prefs.getLong("registeredUserId", -1L); 
124:	pendingC2DMRequestTime = prefs.getLong("pendingC2DMRequestTime", 0); 
125:	pendingSocializeRequestTime = prefs.getLong("pendingSocializeRequestTime", 0); 
126:	lastC2DMRegistrationTime = prefs.getLong("lastC2DMRegistrationTime", 0); 
127:	lastSocializeRegistrationTime = prefs.getLong("lastSocializeRegistrationTime", 0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getInt
45:	getListView().setSelectionFromTop(prefs.getInt("index", 0), prefs.getInt("top", 0)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: edit, getBoolean, getLong
27:	if (prefs.getBoolean("dontshowagain", false)) { return ; } 
-
29:	SharedPreferences.Editor editor = prefs.edit(); 
-
32:	long launch_count = prefs.getLong("launch_count", 0) + 1; 
-
36:	Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0); 
-
44:	!prefs.getBoolean("dontshowagain", false) && 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getInt, getLong, getString
138:	String registrationId=prefs.getString(PROPERTY_REG_ID, ""); 
-
142:	int oldVersion= 
-
195:	long expirationTime= 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
26:	editor = sharedPreferences.edit(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: edit
67:	AndroidMock.expect(context.getSharedPreferences("SocializeSession", Context.MODE_PRIVATE)).andReturn(prefs); 
68:	AndroidMock.expect(prefs.edit()).andReturn(editor); 
-
73:	AndroidMock.replay(prefs); 
-
81:	AndroidMock.verify(prefs); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit, getString
74:	String lastFile = settings.getString(LAST_FILENAME, ""); 
75:	String lastKey = settings.getString(LAST_KEYFILE,""); 
-
102:	SharedPreferences.Editor editor = prefs.edit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString
33:	String username = this.prefs.getString("username", null); 
34:	String password = this.prefs.getString("password", null); 
35:	String apiRoot = prefs.getString("apiRoot", 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString
33:	String username = this.prefs.getString("username", ""); 
34:	String password = this.prefs.getString("password", ""); 
35:	String apiRoot = prefs.getString("apiRoot", 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit, getInt
53:	prefs.edit().putInt(KEY, prefs.getInt("test", 0) + 1).apply(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getLong, getString
26:	session.setAccessToken(savedSession.getString(TOKEN, null)); 
27:	session.setAccessExpires(savedSession.getLong(EXPIRES, 0)); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit, getBoolean, getLong
12:	if (prefs.getBoolean("dontshowagain", false)) { return; } 
-
14:	SharedPreferences.Editor editor = prefs.edit(); 
-
17:	long launch_count = prefs.getLong("launch_count", 0) + 1; 
-
21:	Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString
124:	return sharedPrefs.getString(key, defValue); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString
35:	String username = this.prefs.getString("username", null); 
36:	String password = this.prefs.getString("password", null); 
37:	String apiRoot = prefs.getString("apiRoot", 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit, getInt
53:	prefs.edit().putInt(KEY, prefs.getInt("test", 0) + 1).apply(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString
59:	client=new Twitter(prefs.getString("user", ""), 
60:	prefs.getString("password", "")); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit, getInt, getLong
162:	int numUniqueDaysShown = prefs.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, 0); 
163:	long lastTimeHintWasShown = prefs.getLong(PREF_VOICE_HINT_LAST_TIME_SHOWN, 0); 
-
169:	SharedPreferences.Editor editor = prefs.edit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAll, getStringSet
58:	Object value=prefs.getAll().get(key); 
-
86:	prefs.getStringSet(key, null).toArray(new String[0])); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: edit
177:	cache.edit().clear().commit(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: edit, getBoolean, getLong
21:	if (prefs.getBoolean("dontshowagain", false)) { 
-
25:	SharedPreferences.Editor editor = prefs.edit(); 
-
28:	long launch_count = prefs.getLong("launch_count", 0) + 1; 
-
32:	Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getBoolean, getString
27:	sharedPreferences.getString("listChoice", "None"), 
28:	sharedPreferences.getString("nameChoice", "No name"), 
29:	sharedPreferences.getBoolean("booleanChoice", false)); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit, getInt
64:	if (prefs.getInt(DOUBLE_TAP_TOAST_COUNT, 1) > 0) { 
65:	prefs.edit().putInt(DOUBLE_TAP_TOAST_COUNT, 0).commit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getBoolean, getString
141:	boolean doAutoSync = this.appSettings.getBoolean("doAutoSync", false); 
-
145:	this.appSettings.getString("autoSyncInterval", "1800000"), 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
103:	Editor editor = prefs.edit(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getBoolean, registerOnSharedPreferenceChangeListener
50:	mPrefs.registerOnSharedPreferenceChangeListener(this); 
51:	setSwitchChecked(mPrefs.getBoolean(mKey, mDefValue)); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getInt
90:	mPasswordQuality = prefs.getInt(KEY_PASSWORD_QUALITY, -1); 
91:	mPasswordLength = prefs.getInt(KEY_PASSWORD_LENGTH, -1); 
92:	mPasswordMinUpperCase = prefs.getInt(KEY_PASSWORD_MIN_UPPERCASE, -1); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
172:	Editor editor              = settings.edit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
116:	Editor editor = m_prefs.edit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
103:	Editor editor = prefs.edit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
23:	Editor e = mPrefs.edit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
117:	mPrefs.edit().putBoolean(ANONYMOUS_OPT_IN, true).apply(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
33:	sharedPreferences.edit().clear().commit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
86:	final SharedPreferences.Editor editor = mPreferences.edit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
62:	Editor editor = mPreferences.edit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
52:	sharedPreferences.edit().putString(GUID_KEY, guid).commit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
177:	cache.edit().clear().commit(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: edit
105:	mEditor = mPrefs.edit(); 
Full Snippet Info
7
CodeRank
Related Android SharedPreferences Questions & Answers:
Other Android SharedPreferences Examples
0:	SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
1:	Editor editor = pref.edit();
2:

Read More

9:	public class SessionManager {
10:		// Shared Preferences
11:		SharedPreferences pref;
12:		
13:		// Editor for Shared preferences

Read More

9:	public class SessionManager {
10:		// Shared Preferences
11:		SharedPreferences pref;
12:		
13:		// Editor for Shared preferences

Read More

6:	        // Deletes previously stored password policy.
7:	        super.onDisabled(context, intent);
8:	        SharedPreferences prefs = context.getSharedPreferences(APP_PREF, Activity.MODE_PRIVATE);
9:	        prefs.edit().clear().commit();
10:	    }

Read More

See Code Examples for Android SharedPreferences Methods: