SharedPreferences edit - top ranked examples from Open Source projects

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

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);
	} 
 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:edit
public abstract class EditorHelper<T extends EditorHelper<T>> { 
 
	private final Editor editor;
 
	public EditorHelper(SharedPreferences sharedPreferences) {
		editor = sharedPreferences.edit();
	} 
 
	protected Editor getEditor() {
		return editor;
	} 
 
	public final T clear() { 
		editor.clear();
		return cast(); 
	} 
 
	public final void apply() { 
		SharedPreferencesCompat.apply(editor);
	} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:edit
	} 
 
	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();
		bundle.putString("test", testName);
		Intent intent = new Intent(this, GdxTestActivity.class);
		intent.putExtras(bundle);
 
		startActivity(intent);
	} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:edit
 
    /** 
     * Clears out all token information stored in this cache. 
     */ 
    public void clear() { 
        cache.edit().clear().commit();
    } 
 
    private void serializeKey(String key, Bundle bundle, SharedPreferences.Editor editor)
        throws JSONException { 
        Object value = bundle.get(key);
        if (value == null) {
            // Cannot serialize null values. 
            return; 
        } 
 
        String supportedType = null;
        JSONArray jsonArray = null;
        JSONObject json = new JSONObject();
 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:edit, getBoolean, getInt, getLong
     * @return the wall clock time ({@link System#currentTimeMillis()}) when the 
     * next operation should be attempted -- immediately, if the return value is 
     * before the current time. 
     */ 
    public long getNextTimeMillis(Options options) {
        boolean enabledState = mStorage.getBoolean(PREFIX + "enabledState", true);
        if (!enabledState) return Long.MAX_VALUE;
 
        boolean permanentError = mStorage.getBoolean(PREFIX + "permanentError", false);
        if (permanentError) return Long.MAX_VALUE;
 
        // We do quite a bit of limiting to prevent a clock rollback from totally 
        // hosing the scheduler.  Times which are supposed to be in the past are 
        // clipped to the current time so we don't languish forever. 
 
        int errorCount = mStorage.getInt(PREFIX + "errorCount", 0);
        long now = currentTimeMillis();
        long lastSuccessTimeMillis = getTimeBefore(PREFIX + "lastSuccessTimeMillis", now);
        long lastErrorTimeMillis = getTimeBefore(PREFIX + "lastErrorTimeMillis", now);
        long triggerTimeMillis = mStorage.getLong(PREFIX + "triggerTimeMillis", Long.MAX_VALUE);

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:edit, getLong, getString
 
    private String getIDFromFile(Context ctx) {
        SharedPreferences mSettings = null;
        mSettings = getPreferenceFile();
        mLogging.info(LOGTAG, "Verifying Install Info");
        mUniqueID = mSettings.getString(UNIQUE_KEYID, "");
        if (mUniqueID.length() == 0) {
            // Application First run 
            mLogging.info(LOGTAG,
                    "First Time Running - Generating Unique Install ID"); 
            mIsFirstTimeRunnig = true;
            mIsAValidInstall = true;
            mUniqueID = UUID.randomUUID().toString();
            mInstallTimeStamp = System.currentTimeMillis();
            mTimeStampHash=DigestUtils.shaHex(mUniqueID + Long.toString(mInstallTimeStamp));
            saveToPreferencesFile(mSettings, mUniqueID, mInstallTimeStamp, mTimeStampHash);
            mLogging.info(LOGTAG, "Install Info Saved with Success");
            return mUniqueID;
        } else { 
            mLogging.info(LOGTAG, "Not First Time Running - Validating Install");

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:edit, getInt
        } 
    } 
 
    private int getAndIncrementPref(String pref) {
        final SharedPreferences prefs = mPrefs;
        int value = prefs.getInt(pref, 0);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putInt(pref, value + 1);
        SharedPreferencesCompat.apply(editor);
        return value;
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:edit
		editor.remove(key);
	} 
 
	private void edit () { 
		if (editor == null) {
			editor = sharedPrefs.edit();
		} 
	} 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:edit, getBoolean
        prefs = getSharedPreferences("torch", Context.MODE_WORLD_READABLE);
        Log.i(TAG, "onCreate");
    } 
 
    private void toggleTorch() { 
        if (prefs.getBoolean(KEY_TORCH_ON, false)) // find torch state
            stopTorch(); // torch is on - turn it off 
        else 
            startTorch(); // torch is off, turn it on 
    } 
 
    private void startTorch() { 
        if (!startingTorch) {
            startingTorch = true;
            getCamera(); 
            startPreview(); 
            turnLightOn(); 
            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean(KEY_TORCH_ON, true);
            editor.commit();

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:edit, getBoolean, getInt
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related SharedPreferences edit Questions & Answers:

Other SharedPreferences edit Examples

178:	
179:						// Shared Preferences
180:						Editor e = mSharedPreferences.edit();
181:	
182:						// After getting access token, access token secret
-
323:		private void logoutFromTwitter() {
324:			// Clear the shared preferences
325:			Editor e = mSharedPreferences.edit();
326:			e.remove(PREF_KEY_OAUTH_TOKEN);
327:			e.remove(PREF_KEY_OAUTH_SECRET);

Read More

36:			this._context = context;
37:			pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
38:			editor = pref.edit();
39:		}
40:

Read More

36:			this._context = context;
37:			pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
38:			editor = pref.edit();
39:		}
40:

Read More

7:	        super.onDisabled(context, intent);
8:	        SharedPreferences prefs = context.getSharedPreferences(APP_PREF, Activity.MODE_PRIVATE);
9:	        prefs.edit().clear().commit();
10:	    }
11:	}

Read More

edit Method Overview
Create a new Editor for these preferences, through which you can make modifications to the data in the preferences and atomically commit those changes back to the SharedPreferences object.
See Code Examples for other Android SharedPreferences Methods: