use SharedPreferences.apply() instead (#16632)

This commit is contained in:
minggo 2016-09-30 14:58:30 +08:00 committed by GitHub
parent c046257efc
commit 5785c3fcdd
1 changed files with 6 additions and 6 deletions

View File

@ -620,21 +620,21 @@ public class Cocos2dxHelper {
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0); SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(key, value); editor.putBoolean(key, value);
editor.commit(); editor.apply();
} }
public static void setIntegerForKey(String key, int value) { public static void setIntegerForKey(String key, int value) {
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0); SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putInt(key, value); editor.putInt(key, value);
editor.commit(); editor.apply();
} }
public static void setFloatForKey(String key, float value) { public static void setFloatForKey(String key, float value) {
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0); SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putFloat(key, value); editor.putFloat(key, value);
editor.commit(); editor.apply();
} }
public static void setDoubleForKey(String key, double value) { public static void setDoubleForKey(String key, double value) {
@ -642,21 +642,21 @@ public class Cocos2dxHelper {
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0); SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putFloat(key, (float)value); editor.putFloat(key, (float)value);
editor.commit(); editor.apply();
} }
public static void setStringForKey(String key, String value) { public static void setStringForKey(String key, String value) {
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0); SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putString(key, value); editor.putString(key, value);
editor.commit(); editor.apply();
} }
public static void deleteValueForKey(String key) { public static void deleteValueForKey(String key) {
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0); SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.remove(key); editor.remove(key);
editor.commit(); editor.apply();
} }
public static byte[] conversionEncoding(byte[] text, String fromCharset,String newCharset) public static byte[] conversionEncoding(byte[] text, String fromCharset,String newCharset)