Java Code Examples for android.content.SharedPreferences.Editor#remove()
The following examples show how to use
android.content.SharedPreferences.Editor#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrecacheUMA.java From 365browser with Apache License 2.0 | 6 votes |
/** * Record the precache event. The event is persisted in shared preferences if the native library * is not loaded. If library is loaded, the event will be recorded as UMA metric, and any prior * persisted events are recorded to UMA as well. * @param event the precache event. */ public static void record(int event) { SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences(); long persistent_metric = sharedPreferences.getLong(PREF_PERSISTENCE_METRICS, 0); Editor preferencesEditor = sharedPreferences.edit(); if (LibraryLoader.isInitialized()) { RecordHistogram.recordEnumeratedHistogram( EVENTS_HISTOGRAM, Event.getBitPosition(event), Event.EVENT_END); for (int e : Event.getEventsFromBitMask(persistent_metric)) { RecordHistogram.recordEnumeratedHistogram( EVENTS_HISTOGRAM, Event.getBitPosition(e), Event.EVENT_END); } preferencesEditor.remove(PREF_PERSISTENCE_METRICS); } else { // Save the metric in preferences. persistent_metric = Event.addEventToBitMask(persistent_metric, event); preferencesEditor.putLong(PREF_PERSISTENCE_METRICS, persistent_metric); } preferencesEditor.apply(); }
Example 2
Source File: TalkBackUpdateHelper.java From talkback with Apache License 2.0 | 6 votes |
/** * Changes to use one single pref as dump event bit mask instead of having one pref per event * type. */ private void remapDumpEventPref() { Resources resources = service.getResources(); int[] eventTypes = AccessibilityEventUtils.getAllEventTypes(); int eventDumpMask = 0; Editor editor = sharedPreferences.edit(); for (int eventType : eventTypes) { String prefKey = resources.getString(R.string.pref_dump_event_key_prefix, eventType); if (sharedPreferences.getBoolean(prefKey, false)) { eventDumpMask |= eventType; } editor.remove(prefKey); } if (eventDumpMask != 0) { editor.putInt(resources.getString(R.string.pref_dump_event_mask_key), eventDumpMask); } editor.apply(); }
Example 3
Source File: GeoPackageDatabases.java From geopackage-mapcache-android with MIT License | 6 votes |
/** * Remove the database from the saved preferences * * @param database * @param preserveOverlays */ private void removeDatabaseFromPreferences(String database, boolean preserveOverlays) { Editor editor = settings.edit(); Set<String> databases = settings.getStringSet(databasePreference, new HashSet<String>()); if (databases != null && databases.contains(database)) { Set<String> newDatabases = new HashSet<String>(); newDatabases.addAll(databases); newDatabases.remove(database); editor.putStringSet(databasePreference, newDatabases); } editor.remove(getTileTablesPreferenceKey(database)); editor.remove(getFeatureTablesPreferenceKey(database)); if (!preserveOverlays) { editor.remove(getFeatureOverlayTablesPreferenceKey(database)); deleteTableFiles(database); } editor.commit(); }
Example 4
Source File: SharePreUtil.java From Aria with Apache License 2.0 | 5 votes |
/** * 删除键值对 */ public static void removeKey(String preName, Context context, String key) { SharedPreferences pre = context.getSharedPreferences(preName, Context.MODE_PRIVATE); Editor editor = pre.edit(); editor.remove(key); editor.commit(); }
Example 5
Source File: IdentityKeyUtil.java From Silence with GNU General Public License v3.0 | 5 votes |
public static void remove(Context context, String key) { SharedPreferences preferences = context.getSharedPreferences(MasterSecretUtil.PREFERENCES_NAME, 0); Editor preferencesEditor = preferences.edit(); preferencesEditor.remove(key); if (!preferencesEditor.commit()) throw new AssertionError("failed to remove identity key/value to shared preferences"); }
Example 6
Source File: Preference.java From product-emm with Apache License 2.0 | 5 votes |
public static void removePreference(Context context, String key){ SharedPreferences mainPref = context.getSharedPreferences(context.getResources() .getString(R.string.shared_pref_package), Context.MODE_PRIVATE ); if (mainPref.contains(key)) { Editor editor = mainPref.edit(); editor.remove(key); editor.commit(); } }
Example 7
Source File: PreferVisitor.java From BaseProject with Apache License 2.0 | 5 votes |
/** * 批量移除喜好配置中的keys * @param spFileName * @param spKeys */ public boolean batchRemoveKeys(String spFileName, String... spKeys) { if (spKeys != null && spKeys.length > 0) { Editor spFileEditor = getEditor(spFileName); for (String toRemoveKey : spKeys) { spFileEditor.remove(toRemoveKey); } return spFileEditor.commit(); } return false; }
Example 8
Source File: Prefs.java From PS4-Payload-Sender-Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param key The name of the preference to modify. * @param value The new value for the preference. * @see Editor#putStringSet(String, Set) */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static void putStringSet(final String key, final Set<String> value) { final Editor editor = getPreferences().edit(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { editor.putStringSet(key, value); } else { // Workaround for pre-HC's lack of StringSets int stringSetLength = 0; if (mPrefs.contains(key + LENGTH)) { // First read what the value was stringSetLength = mPrefs.getInt(key + LENGTH, -1); } editor.putInt(key + LENGTH, value.size()); int i = 0; for (String aValue : value) { editor.putString(key + "[" + i + "]", aValue); i++; } for (; i < stringSetLength; i++) { // Remove any remaining values editor.remove(key + "[" + i + "]"); } } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { editor.commit(); } else { editor.apply(); } }
Example 9
Source File: SharedPreferencesUtil.java From HaoReader with GNU General Public License v3.0 | 5 votes |
/** * 从文件中删除数据 * * @param context * @param key */ public static void deleteData(Context context, String key) { SharedPreferences sharedPreferences = context .getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.remove(key); editor.apply(); }
Example 10
Source File: PreferenceUtils.java From LeisureRead with Apache License 2.0 | 5 votes |
public static void remove(String... keys) { if (keys != null) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences( LeisureReadApp.getAppContext()); Editor editor = sharedPreferences.edit(); for (String key : keys) { editor.remove(key); } editor.commit(); } }
Example 11
Source File: AlarmClockService.java From AlarmOn with Apache License 2.0 | 5 votes |
public void fixPersistentSettings() { final String badDebugName = "DEBUG_MODE\""; final String badNotificationName = "NOTFICATION_ICON"; final String badLockScreenName = "LOCK_SCREEN\""; final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Map<String, ?> prefNames = prefs.getAll(); // Don't do anything if the bad preferences have already been fixed. if (!prefNames.containsKey(badDebugName) && !prefNames.containsKey(badNotificationName) && !prefNames.containsKey(badLockScreenName)) { return; } Editor editor = prefs.edit(); if (prefNames.containsKey(badDebugName)) { editor.putString(AppSettings.DEBUG_MODE, prefs.getString(badDebugName, null)); editor.remove(badDebugName); } if (prefNames.containsKey(badNotificationName)){ editor.putBoolean(AppSettings.NOTIFICATION_ICON, prefs.getBoolean(badNotificationName, true)); editor.remove(badNotificationName); } if (prefNames.containsKey(badLockScreenName)) { editor.putString(AppSettings.LOCK_SCREEN, prefs.getString(badLockScreenName, null)); editor.remove(badLockScreenName); } editor.apply(); }
Example 12
Source File: XmppManager.java From androidpn-client with Apache License 2.0 | 5 votes |
public void disconnect() { Log.d(LOGTAG, "disconnect()..."); if (sharedPrefs.contains(Constants.XMPP_LOGGEDIN)) { Editor editor = sharedPrefs.edit(); editor.remove(Constants.XMPP_LOGGEDIN); editor.remove(Constants.XMPP_REGISTERED); editor.apply(); } terminatePersistentConnection(); }
Example 13
Source File: CommSharedUtil.java From AndroidMultiLanguage with Apache License 2.0 | 4 votes |
public void remove(String key) { Editor edit = sharedPreferences.edit(); edit.remove(key); edit.apply(); }
Example 14
Source File: SPUtil.java From UIWidget with Apache License 2.0 | 4 votes |
public static boolean remove(Context context, String fileName, String key) { SharedPreferences sp = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); Editor editor = sp.edit(); editor.remove(key); return editor.commit(); }
Example 15
Source File: SdkPreference.java From android-project-wo2b with Apache License 2.0 | 4 votes |
public static boolean removeTemp(String key) { Editor editor = editTemp(); editor.remove(key); return editor.commit(); }
Example 16
Source File: SharedUtil.java From FileManager with Apache License 2.0 | 4 votes |
public static void remove(Context context, String key) { SharedPreferences sharedPreferences = getDefaultSharedPreferences(context); Editor edit = sharedPreferences.edit(); edit.remove(key); edit.commit(); }
Example 17
Source File: SdkPreference.java From android-project-wo2b with Apache License 2.0 | 4 votes |
public static boolean remove(String key) { Editor editor = edit(); editor.remove(key); return editor.commit(); }
Example 18
Source File: ServiceManager.java From androidpn-client with Apache License 2.0 | 4 votes |
public void setSettings() { // apiKey = getMetaDataValue("ANDROIDPN_API_KEY"); // Log.i(LOGTAG, "apiKey=" + apiKey); // // if (apiKey == null) { // // Log.e(LOGTAG, "Please set the androidpn api key in the manifest file."); // // throw new RuntimeException(); // // } SharedPreferences mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); apiKey = mySharedPreferences.getString("prefApikey", "1234567890").trim(); xmppHost = mySharedPreferences.getString("prefXmpphost", "192.168.0.1").trim(); xmppPort = mySharedPreferences.getString("prefXmppport", "5222").trim(); email = mySharedPreferences.getString("prefEmail", "").trim(); pass = mySharedPreferences.getString("prefPass", "").trim(); user = mySharedPreferences.getString("prefUser", "").trim(); name = mySharedPreferences.getString("prefName", "").trim(); boolean prefNtfy = mySharedPreferences.getBoolean("prefNtfy",true); boolean prefSound = mySharedPreferences.getBoolean("prefSound",true); boolean prefVibrate = mySharedPreferences.getBoolean("prefVibrate",true); boolean prefToast = mySharedPreferences.getBoolean("prefToast",false); Log.i(LOGTAG, "apiKey=" + apiKey); Log.i(LOGTAG, "xmppHost=" + xmppHost); Log.i(LOGTAG, "xmppPort=" + xmppPort); Log.i(LOGTAG, "user=" + user); Log.i(LOGTAG, "name=" + name); Log.i(LOGTAG, "email=" + email); sharedPrefs = context.getSharedPreferences( Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); Editor editor = sharedPrefs.edit(); editor.putString(Constants.API_KEY, apiKey); editor.putString(Constants.VERSION, version); editor.putString(Constants.XMPP_HOST, xmppHost); editor.putString(Constants.XMPP_USERNAME, user); editor.putString(Constants.XMPP_PASSWORD, pass); editor.putString(Constants.XMPP_EMAIL, email); editor.putString(Constants.NAME, name); try { editor.remove(Constants.SETTINGS_NOTIFICATION_ENABLED); editor.remove(Constants.SETTINGS_SOUND_ENABLED); editor.remove(Constants.SETTINGS_VIBRATE_ENABLED); editor.remove(Constants.SETTINGS_TOAST_ENABLED); } catch (Exception e) { Log.d(LOGTAG, "Settings not removed"); } editor.putBoolean(Constants.SETTINGS_NOTIFICATION_ENABLED, prefNtfy); editor.putBoolean(Constants.SETTINGS_SOUND_ENABLED, prefSound); editor.putBoolean(Constants.SETTINGS_VIBRATE_ENABLED, prefVibrate); editor.putBoolean(Constants.SETTINGS_TOAST_ENABLED, prefToast); editor.putInt(Constants.XMPP_PORT, Integer.parseInt(xmppPort.trim())); editor.putString(Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, callbackActivityPackageName); editor.putString(Constants.CALLBACK_ACTIVITY_CLASS_NAME, callbackActivityClassName); editor.apply(); // Log.i(LOGTAG, "sharedPrefs=" + sharedPrefs.toString()); }
Example 19
Source File: SimpleSharedPreference.java From VideoMeeting with Apache License 2.0 | 4 votes |
public void remove(String key) { Editor editor = mPref.edit(); editor.remove(key); editor.apply(); }
Example 20
Source File: MainActivity.java From Ecommerce-Retronight-Android with Creative Commons Zero v1.0 Universal | 3 votes |
public void clearToken() { Editor editor = sharedPreferences.edit(); editor.remove(TOKEN_KEY); editor.commit(); }