本文整理汇总了Java中android.content.SharedPreferences.Editor方法的典型用法代码示例。如果您正苦于以下问题:Java SharedPreferences.Editor方法的具体用法?Java SharedPreferences.Editor怎么用?Java SharedPreferences.Editor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.SharedPreferences
的用法示例。
在下文中一共展示了SharedPreferences.Editor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPersonName
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static void setPersonName(String personIdToAdd, String personName, String personGroupId, Context context) {
SharedPreferences personIdNameMap =
context.getSharedPreferences(personGroupId + "PersonIdNameMap", Context.MODE_PRIVATE);
SharedPreferences.Editor personIdNameMapEditor = personIdNameMap.edit();
personIdNameMapEditor.putString(personIdToAdd, personName);
personIdNameMapEditor.commit();
Set<String> personIds = getAllPersonIds(personGroupId, context);
Set<String> newPersonIds = new HashSet<>();
for (String personId: personIds) {
newPersonIds.add(personId);
}
newPersonIds.add(personIdToAdd);
SharedPreferences personIdSet =
context.getSharedPreferences(personGroupId + "PersonIdSet", Context.MODE_PRIVATE);
SharedPreferences.Editor personIdSetEditor = personIdSet.edit();
personIdSetEditor.putStringSet("PersonIdSet", newPersonIds);
personIdSetEditor.commit();
}
示例2: deleteSettings
import android.content.SharedPreferences; //导入方法依赖的package包/类
private int deleteSettings(int uid) {
int rows = 0;
String sUid = Integer.toString(uid);
SharedPreferences prefs = getContext().getSharedPreferences(PREF_SETTINGS, Context.MODE_WORLD_READABLE);
SharedPreferences.Editor editor = prefs.edit();
for (String pref : prefs.getAll().keySet()) {
String[] component = pref.split("\\.");
if (component.length >= 3 && component[2].equals(sUid)) {
Util.log(null, Log.INFO, "Removed setting=" + pref + " uid=" + uid);
editor.remove(pref);
rows++;
}
}
editor.commit();
setPrefFileReadable(PREF_SETTINGS);
return rows;
}
示例3: updateLockStatus
import android.content.SharedPreferences; //导入方法依赖的package包/类
private void updateLockStatus ( Boolean value )
{
SharedPreferences prefs = getSharedPreferences( Constant.PREF_NAME , 0 );
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean( Constant.FACE_LOCK_STATUS_PREF , value );
editor.commit();
}
示例4: saveSavedLogin
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static void saveSavedLogin(String info) {
if (wifiName != null) {
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString(wifiName, info);
editor.commit();
}
}
示例5: onLoginButtonClick
import android.content.SharedPreferences; //导入方法依赖的package包/类
@OnClick(R.id.login_button)
public void onLoginButtonClick() {
if(checkBox.isChecked()){
SharedPreferences settings = getSharedPreferences(KEY_USERNAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("User", userLogin.getEditText().getText().toString());
editor.apply();
}
attemptLogin();
}
示例6: remove
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* 移除某个key值已经对应的值
* @param context
* @param key
*/
public static void remove(Context context, String key) {
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.remove(key);
SharedPreferencesCompat.apply(editor);
}
示例7: storeImmediate
import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
@SuppressLint("ApplySharedPref") // this is the intended behavior
public void storeImmediate(String key, Object toStore) {
final SharedPreferences.Editor editor = mSp.edit();
storeObject(editor, key, toStore);
editor.commit();
}
示例8: onTokenRefresh
import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void onTokenRefresh() {
super.onTokenRefresh();
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d("Firebase", "Token is : "+refreshedToken);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("firebaseToken", refreshedToken);
editor.putString("firebaseTokenRefreshed", "false");
editor.apply();
}
示例9: deleteToken
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void deleteToken()
{
SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.clear();
editor.apply();
}
示例10: clearOnlineStatus
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* @param context
*/
public static void clearOnlineStatus(Context context){
SharedPreferences userInfos=context.getSharedPreferences(SPNAME, 0);
SharedPreferences.Editor editor = userInfos.edit();
editor.remove("online");
editor.commit();
}
示例11: clear
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* 清除所有数据
*/
public static void clear(Context context){
SharedPreferences sp = context.getSharedPreferences(getSpName(context),Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.clear();
org.androidannotations.api.sharedpreferences.SharedPreferencesCompat.apply(editor);
}
示例12: setKokisShort
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static void setKokisShort(String key, short value){
String convertedShortString = convertShortToString(value);
final SharedPreferences.Editor editor = getSharedPreferencesObject().edit();
editor.putString(key, convertedShortString);
editor.commit();
}
示例13: setDownloadType
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* Function to set witch type of download you do
*
* @param type integer refer to download type
*/
public static void setDownloadType(int type) {
SharedPreferences.Editor editor = OpenConfigPreferences().edit();
editor.putInt(AppConstants.Preferences.DOWNLOAD_TYPE, type);
editor.apply();
}
示例14: putInt
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* 保存一个int类型的值!
*/
public static void putInt(String key, int value) {
SharedPreferences.Editor editor = getSharedPreference(CONFIG).edit();
editor.putInt(key, value).apply();
}
示例15: clearPreference
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static void clearPreference() {
final SharedPreferences.Editor editor = getSharedPreferences().edit();
editor.clear();
editor.commit();
}