本文整理匯總了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();
}