當前位置: 首頁>>代碼示例>>Java>>正文


Java SharedPreferences.Editor方法代碼示例

本文整理匯總了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();
}
 
開發者ID:interritus1996,項目名稱:memento-app,代碼行數:21,代碼來源:StorageHelper.java

示例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;
}
 
開發者ID:ukanth,項目名稱:XPrivacy,代碼行數:18,代碼來源:PrivacyProvider.java

示例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();
}
 
開發者ID:informramiz,項目名稱:Android-Face-Recognition,代碼行數:9,代碼來源:EnableFaceLockActivity.java

示例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();
    }
}
 
開發者ID:jsparber,項目名稱:CaptivePortalAutologin,代碼行數:8,代碼來源:CaptivePortalLoginActivity.java

示例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();

}
 
開發者ID:hacktoberfest17,項目名稱:programming,代碼行數:14,代碼來源:Login.java

示例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);
}
 
開發者ID:li-yu,項目名稱:FakeWeather,代碼行數:13,代碼來源:SPUtil.java

示例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();
}
 
開發者ID:jibbo,項目名稱:SweetPrefs,代碼行數:8,代碼來源:SharedPreferenceStorage.java

示例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();

}
 
開發者ID:kunalrmhatre,項目名稱:fussroll,代碼行數:15,代碼來源:GetFirebaseToken.java

示例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();
}
 
開發者ID:ThomasDelaney,項目名稱:TapIn,代碼行數:9,代碼來源:messageTokenManager.java

示例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();
}
 
開發者ID:funnyzhaov,項目名稱:Tribe,代碼行數:10,代碼來源:UserSharedPreferences.java

示例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);
}
 
開發者ID:popo1379,項目名稱:popomusic,代碼行數:11,代碼來源:SPUtil.java

示例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();
}
 
開發者ID:PrihanNimsara,項目名稱:KokisAndroidLibrary,代碼行數:7,代碼來源:Kokis.java

示例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();
}
 
開發者ID:fekracomputers,項目名稱:QuranAndroid,代碼行數:11,代碼來源:AppPreference.java

示例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();
}
 
開發者ID:joelan,項目名稱:ClouldReader,代碼行數:8,代碼來源:SPUtils.java

示例15: clearPreference

import android.content.SharedPreferences; //導入方法依賴的package包/類
public static void clearPreference() {
    final SharedPreferences.Editor editor = getSharedPreferences().edit();
    editor.clear();
    editor.commit();
}
 
開發者ID:chengkun123,項目名稱:ReadMark,代碼行數:6,代碼來源:SPUtils.java


注:本文中的android.content.SharedPreferences.Editor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。