Android SharedPreferences - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android SharedPreferences class.

This code example shows how to use the following methods: edit
	public final void remove() { 
		apply(edit().remove(key));
	} 
 
	protected Editor edit() {
		return sharedPreferences.edit();
	} 
 
	protected final void apply(Editor editor) {
		SharedPreferencesCompat.apply(editor);
	} 
 
} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: contains, edit
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getLong, getString
	} 
	 
	public void load(Context context) {
		if(!loaded) {
			SharedPreferences prefs = context.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE);
			c2DMRegistrationId = prefs.getString("c2DMRegistrationId", null);
			registeredUserId = prefs.getLong("registeredUserId", -1L);
			pendingC2DMRequestTime = prefs.getLong("pendingC2DMRequestTime", 0);
			pendingSocializeRequestTime = prefs.getLong("pendingSocializeRequestTime", 0);
			lastC2DMRegistrationTime = prefs.getLong("lastC2DMRegistrationTime", 0);
			lastSocializeRegistrationTime = prefs.getLong("lastSocializeRegistrationTime", 0);
			 
			if(logger != null && logger.isDebugEnabled()) {
				logger.debug("Loaded notification state with registration id [" +
						c2DMRegistrationId +
						"], user id [" + 
						registeredUserId +
						"]"); 
			}		 
		} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getInt
		GdxTests.tests.add(MatrixTest.class); 
		List<String> testNames = GdxTests.getNames();
		setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, testNames));
 
		prefs = getSharedPreferences("libgdx-tests", Context.MODE_PRIVATE);
		getListView().setSelectionFromTop(prefs.getInt("index", 0), prefs.getInt("top", 0));
	} 
 
	protected void onListItemClick (ListView listView, View view, int position, long id) {
		super.onListItemClick(listView, view, position, id);
 
		Editor editor = prefs.edit();
		editor.putInt("index", listView.getFirstVisiblePosition());
		editor.putInt("top", listView.getChildAt(0) == null ? 0 : listView.getChildAt(0).getTop());
		editor.commit();
 
		Object o = this.getListAdapter().getItem(position);
		String testName = o.toString();
 
		Bundle bundle = new Bundle();
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: edit, getBoolean, getLong
    private final static int LAUNCHES_UNTIL_PROMPT = 7;
     
    public static void appLaunched(Context mContext) {
        SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
 
        if (prefs.getBoolean("dontshowagain", false)) { return ; }
         
        SharedPreferences.Editor editor = prefs.edit();
         
        // Increment launch counter 
        long launch_count = prefs.getLong("launch_count", 0) + 1;
        editor.putLong("launch_count", launch_count);
 
        // Get date of first launch 
        Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
        if (date_firstLaunch == 0) {
            date_firstLaunch = System.currentTimeMillis();
            editor.putLong("date_firstlaunch", date_firstLaunch);
        } 
         

8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

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: