Java Code Examples for android.content.SharedPreferences.Editor#clear()

The following examples show how to use android.content.SharedPreferences.Editor#clear() . 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: AccessManager.java    From K2AUSBKeyboard with GNU General Public License v3.0 6 votes vote down vote up
public static void removeAccessToken(Context ctx, String hostPackage,
		String accessToken) {
	SharedPreferences prefs = getPrefsForHost(ctx, hostPackage);

	Log.d(_tag, "removing AccessToken.");
	if (prefs.getString(PREF_KEY_TOKEN, "").equals(accessToken))
	{
		Editor edit = prefs.edit();
		edit.clear();
		edit.commit();

	}
	
	SharedPreferences hostPrefs = ctx.getSharedPreferences("KP2A.PluginAccess.hosts", Context.MODE_PRIVATE);
	if (hostPrefs.contains(hostPackage))
	{
		hostPrefs.edit().remove(hostPackage).commit();
	}
 
}
 
Example 2
Source File: AccessTokenKeeper.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
/**
 * 清空 SharedPreferences 中 Token信息。
 * 
 * @param context 应用程序上下文环境
 */
public static void clear(Context context) {
    if (null == context) {
        return;
    }
    
    SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
    Editor editor = pref.edit();
    editor.clear();
    editor.commit();
}
 
Example 3
Source File: AccessTokenKeeper.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
/**
 * 清空 SharedPreferences 中 Token信息。
 * 
 * @param context 应用程序上下文环境
 */
public static void clear(Context context) {
    if (null == context) {
        return;
    }
    
    SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
    Editor editor = pref.edit();
    editor.clear();
    editor.commit();
}
 
Example 4
Source File: PreferenceBackupHelper.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Imports all preferences from the given stream.
 * 
 * @param reader the stream to read from
 * @param preferences the shared preferences to edit
 * @throws IOException if there are any errors while reading
 */
@SuppressLint("CommitPrefEdits")
public void importPreferences(DataInputStream reader, SharedPreferences preferences)
    throws IOException {
  Editor editor = preferences.edit();
  editor.clear();

  int numPreferences = reader.readInt();
  for (int i = 0; i < numPreferences; i++) {
    String name = reader.readUTF();
    byte typeId = reader.readByte();
    readAndSetPreference(name, typeId, reader, editor);
  }
  ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
}
 
Example 5
Source File: PreferenceUtils.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
public static void clearPreference(Context context,
		final SharedPreferences p) {
	final Editor editor = p.edit();
	editor.clear();
	editor.commit();

}
 
Example 6
Source File: PersistentCookieStore.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public boolean removeAll() {
    Editor prefsWriter = this.cookiePrefs.edit();
    prefsWriter.clear();
    prefsWriter.commit();
    this.cookies.clear();
    return true;
}
 
Example 7
Source File: PreferencesOperations.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
public static void clearPreferences(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Editor prefEdit = prefs.edit();
    prefEdit.clear();
    boolean cleared = prefEdit.commit();
    if (cleared) {
        Timber.d("clearPreferences(): Preferences cleared");
        Toast.makeText(context, "Preferences cleared", Toast.LENGTH_LONG).show();
    } else {
        Timber.e("clearPreferences(): Failed to clear preferences");
    }
}
 
Example 8
Source File: PreferenceBackupHelperTest.java    From mytracks with Apache License 2.0 5 votes vote down vote up
public void testExportImportPreferences() throws Exception {
  // Populate with some initial values
  Editor editor = preferences.edit();
  editor.clear();
  editor.putBoolean("bool1", true);
  editor.putBoolean("bool2", false);
  editor.putFloat("flt1", 3.14f);
  editor.putInt("int1", 42);
  editor.putLong("long1", 123456789L);
  editor.putString("str1", "lolcat");
  ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);

  // Export it
  byte[] exported = preferenceBackupHelper.exportPreferences(preferences);

  // Mess with the previous values
  editor = preferences.edit();
  editor.clear();
  editor.putString("str2", "Shouldn't be there after restore");
  editor.putBoolean("bool2", true);
  ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);

  // Import it back
  preferenceBackupHelper.importPreferences(exported, preferences);

  assertFalse(preferences.contains("str2"));
  assertTrue(preferences.getBoolean("bool1", false));
  assertFalse(preferences.getBoolean("bool2", true));
  assertEquals(3.14f, preferences.getFloat("flt1", 0.0f));
  assertEquals(42, preferences.getInt("int1", 0));
  assertEquals(123456789L, preferences.getLong("long1", 0));
  assertEquals("lolcat", preferences.getString("str1", ""));
}
 
Example 9
Source File: FilePicker.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPause() {
    super.onPause();
    // save the current directory
    Editor editor = getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE).edit();
    editor.clear();
    if (this.currentDirectory != null) {
        editor.putString(CURRENT_DIRECTORY, this.currentDirectory.getAbsolutePath());
    }
    editor.commit();
}
 
Example 10
Source File: SpUtil.java    From loco-answers with GNU General Public License v3.0 4 votes vote down vote up
public void clear() {
    Editor editor = mPref.edit();
    editor.clear();
    editor.apply();
}
 
Example 11
Source File: PreferencesMigrator.java    From Linphone4Android with GNU General Public License v3.0 4 votes vote down vote up
private void deleteAllOldPreferences() {
	Editor editor = mOldPrefs.edit();
	editor.clear();
	editor.commit();
}
 
Example 12
Source File: PreferenceUtil.java    From dcs-sdk-java with Apache License 2.0 4 votes vote down vote up
public static void clear(Context context, String spName) {
    SharedPreferences sp = context.getSharedPreferences(spName, Context.MODE_PRIVATE);
    Editor editor = sp.edit();
    editor.clear();
    editSubmit(editor);
}
 
Example 13
Source File: PreferenceUtils.java    From imsdk-android with MIT License 4 votes vote down vote up
public static void clearPreference(Context context, final SharedPreferences p) {
    final Editor editor = p.edit();
    editor.clear();
    editor.commit();
}
 
Example 14
Source File: PreferenceUtils.java    From BmapLite with Apache License 2.0 4 votes vote down vote up
public void clear(){
    Editor ed = preference.edit();
    ed.clear();
    ed.apply();
}
 
Example 15
Source File: SharedPreferenceUtils.java    From letv with Apache License 2.0 4 votes vote down vote up
public static void clear(Context context) {
    Editor editor = context.getSharedPreferences(FILE_NAME, 0).edit();
    editor.clear();
    SharedPreferencesCompat.apply(editor);
}
 
Example 16
Source File: SharedPreferenceUtils.java    From letv with Apache License 2.0 4 votes vote down vote up
public static void clear(Context context, String fileName) {
    Editor editor = context.getSharedPreferences(fileName, 0).edit();
    editor.clear();
    SharedPreferencesCompat.apply(editor);
}
 
Example 17
Source File: SimpleSharedPreference.java    From VideoMeeting with Apache License 2.0 4 votes vote down vote up
public void clear() {
	Editor editor = mPref.edit();
	editor.clear();
       editor.apply();
}
 
Example 18
Source File: PreferenceUtils.java    From WeGit with Apache License 2.0 4 votes vote down vote up
public static void clearPreference(Context context,
		final SharedPreferences p) {
	final Editor editor = p.edit();
	editor.clear();
	editor.commit();
}
 
Example 19
Source File: PageApp.java    From TvLauncher with Apache License 2.0 4 votes vote down vote up
public void saveAppMoveStatus() {

        SharedPreferences mSharedPreferences = thisActivity.getSharedPreferences("app_order", Context.MODE_PRIVATE);
        Editor editor = mSharedPreferences.edit();

        editor.clear();

        for (int i = 0; i < mAppInfos.size(); i++) {

            editor.putInt(mAppInfos.get(i).mAppName, i);

        }

        editor.apply();

    }
 
Example 20
Source File: MapPreferences.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public void clear() {
    Editor editor = ctx.getSharedPreferences(PREFERENCES_FILE, Activity.MODE_PRIVATE).edit();
    editor.clear();
    editor.apply();
}