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


Java SharedPreferences.edit方法代碼示例

本文整理匯總了Java中android.content.SharedPreferences.edit方法的典型用法代碼示例。如果您正苦於以下問題:Java SharedPreferences.edit方法的具體用法?Java SharedPreferences.edit怎麽用?Java SharedPreferences.edit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.SharedPreferences的用法示例。


在下文中一共展示了SharedPreferences.edit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onSaveInstanceState

import android.content.SharedPreferences; //導入方法依賴的package包/類
@Override
protected void onSaveInstanceState(Bundle outState) {
	super.onSaveInstanceState(outState);

	if (mFileName != null && mDocView != null) {
		outState.putString("FileName", mFileName);

		// Store current page in the prefs against the file name,
		// so that we can pick it up each time the file is loaded
		// Other info is needed only for screen-orientation change,
		// so it can go in the bundle
		SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
		SharedPreferences.Editor edit = prefs.edit();
		edit.putInt("page"+mFileName, mDocView.getDisplayedViewIndex());
		edit.commit();
	}

	if (!mButtonsVisible)
		outState.putBoolean("ButtonsHidden", true);

	if (mTopBarMode == TopBarMode.Search)
		outState.putBoolean("SearchMode", true);

	if (mReflow)
		outState.putBoolean("ReflowMode", true);
}
 
開發者ID:ArtifexSoftware,項目名稱:mupdf-android-viewer-old,代碼行數:27,代碼來源:MuPDFActivity.java

示例2: putValue

import android.content.SharedPreferences; //導入方法依賴的package包/類
public static void putValue(Context context, String key, Object value) {
	if (value==null){
		return;
	}
	String type = value.getClass().getSimpleName();
	SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
	SharedPreferences.Editor editor = sharedPreferences.edit();
	if ("Integer".equals(type)) {
		editor.putInt(key, (Integer) value);
	} else if ("Boolean".equals(type)) {
		editor.putBoolean(key, (Boolean) value);
	} else if ("String".equals(type)) {
		editor.putString(key, (String) value);
	} else if ("Float".equals(type)) {
		editor.putFloat(key, (Float) value);
	} else if ("Long".equals(type)) {
		editor.putLong(key, (Long) value);
	}
	editor.commit();
}
 
開發者ID:zhuyu1022,項目名稱:amap,代碼行數:21,代碼來源:SharedUtil.java

示例3: onStop

import android.content.SharedPreferences; //導入方法依賴的package包/類
@Override
protected void onStop() {
    super.onStop();

    if (mGoogleApiClient.isConnected()) {
        mGoogleApiClient.disconnect();
    }

    SharedPreferences prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean("isTracking", mTrackingBtn.isSelected());
    if (mMap != null) {
        CameraPosition cameraPosition = mMap.getCameraPosition();
        editor.putFloat("cameraLat", (float) cameraPosition.target.latitude);
        editor.putFloat("cameraLon", (float) cameraPosition.target.longitude);
        editor.putFloat("cameraZoom", cameraPosition.zoom);
    }
    editor.putString("poiFile", poiFile);
    editor.putString("mapFile", mapFile);
    editor.putString("themeFile", themeFile);
    editor.putStringSet("gpxFiles", mGpxManager.getGpxList());
    editor.putInt("coorSetting", CoorSysList.coorSetting);
    editor.apply(); //important, otherwise it wouldn't save.
}
 
開發者ID:typebrook,項目名稱:FiveMinsMore,代碼行數:25,代碼來源:MapsActivity.java

示例4: migrate

import android.content.SharedPreferences; //導入方法依賴的package包/類
public synchronized static void migrate(Context context) {

        SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.cz_dvratil_fbeventsync_preferences), Context.MODE_MULTI_PROCESS);

        int version = prefs.getInt(context.getString(R.string.cfg_prefs_version), 0);
        // Nothing to do
        if (version == PREFERENCES_VERSION) {
            return;
        }

        SharedPreferences.Editor editor = prefs.edit();

        if (version < 1) {
            updateToVersion1(prefs, editor, context);
        }

        editor.putInt(context.getString(R.string.cfg_prefs_version), PREFERENCES_VERSION);
        editor.apply();
    }
 
開發者ID:danvratil,項目名稱:FBEventSync,代碼行數:20,代碼來源:PreferencesMigrator.java

示例5: saveToSettings

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * Save to settings and clear map from null values  return false if nothing to send
 * @param context
 */
boolean saveToSettings(Context context)
{
    SharedPreferences preferences = HelperFunctions.getWebTrekkSharedPreference(context);
    SharedPreferences.Editor editor = preferences.edit();

    //Save standard parameters and remove nulls
    saveToSettingAndRemoveNullItemsProcess(context, editor, mParameters, "");

    //Save custom parameters and remove nulls
    saveToSettingAndRemoveNullItemsProcess(context, editor, mCustomParameters, "cdb");

    editor.apply();

    return !mCustomParameters.isEmpty() || !mParameters.isEmpty();
}
 
開發者ID:Webtrekk,項目名稱:webtrekk-android-sdk,代碼行數:20,代碼來源:WebtrekkUserParameters.java

示例6: clear

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
    * 清除所有數據
    * @param context
    */
   public static void clear(Context context)
   {
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.clear();
SharedPreferencesCompat.apply(editor);
   }
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:12,代碼來源:SPUtils.java

示例7: savePrefs

import android.content.SharedPreferences; //導入方法依賴的package包/類
public static void savePrefs(Context context, int value, String prefs_key) {
    SharedPreferences settings = context.getSharedPreferences(MainActivity.PREFS_NAME, MODE_PRIVATE);
    SharedPreferences.Editor editor = settings.edit();

    editor.putInt(prefs_key, value);
    editor.apply();
}
 
開發者ID:Cesarsk,項目名稱:Say_it,代碼行數:8,代碼來源:UtilitySharedPrefs.java

示例8: 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:ebridfighter,項目名稱:GongXianSheng,代碼行數:14,代碼來源:SPUtils.java

示例9: remove

import android.content.SharedPreferences; //導入方法依賴的package包/類
public static void remove(String name) {
    SharedPreferences sp = getSP(name);
    if (sp == null) {
        ContentResolver cr = mContext.getContentResolver();
        Uri uri = Uri.parse(CONTENT_URI + SEPARATOR + TYPE_LONG + SEPARATOR + name);
        cr.delete(uri, null, null);
    } else {
        SharedPreferences.Editor editor = sp.edit();
        editor.remove(name);
        editor.commit();
    }
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:13,代碼來源:SPHelper.java

示例10: save

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void save(Gpx2FitOptions options) {
    Application app = getApplication();
    SharedPreferences mPrefs=app.getSharedPreferences(app.getApplicationInfo().name, Context.MODE_PRIVATE);
    SharedPreferences.Editor ed=mPrefs.edit();
    Gson gson = new Gson();
    ed.putString(options.getClass().getName(), gson.toJson(options));
    ed.apply();
}
 
開發者ID:gimportexportdevs,項目名稱:gexporter,代碼行數:9,代碼來源:MainActivity.java

示例11: putFloat

import android.content.SharedPreferences; //導入方法依賴的package包/類
private static void putFloat(String key, float value) {

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(
        BilibiliApp.getInstance());
    Editor editor = sharedPreferences.edit();
    editor.putFloat(key, value);
    editor.apply();
  }
 
開發者ID:MUFCRyan,項目名稱:BilibiliClient,代碼行數:9,代碼來源:PreferenceUtil.java

示例12: reset

import android.content.SharedPreferences; //導入方法依賴的package包/類
private void reset(String network) {
    SharedPreferences other = getSharedPreferences(network, Context.MODE_PRIVATE);
    SharedPreferences.Editor edit = other.edit();
    for (String key : other.getAll().keySet())
        edit.remove(key);
    edit.apply();
    fillApplicationList();
    BlackHoleService.reload(network, ActivityMain.this);
}
 
開發者ID:shivam141296,項目名稱:Android-Firewall,代碼行數:10,代碼來源:ActivityMain.java

示例13: updateSharedPreferences

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * Updates the default {@link SharedPreferences} with information regarding state of sync
 * task and the sync mode. This is necessary because if user pressed home button and then
 * relaunches app by clicking app icon, app has to be aware if any sync task is still in
 * progress.
 * @param context Application context
 * @param isSyncRunning Boolean that states if sync task still running
 * @param syncMode Integer indicating
 */
public static synchronized void updateSharedPreferences(Context context, boolean isSyncRunning, int syncMode) {
    DebugLog.logMethod();
    SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(context.getApplicationContext());
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putBoolean(Constants.IS_SYNC_RUNNING, isSyncRunning);
    editor.putInt(Constants.SYNC_MODE, syncMode);
    editor.apply();
}
 
開發者ID:darsh2,項目名稱:CouponsTracker,代碼行數:19,代碼來源:Utilities.java

示例14: toggleSaveToGallery

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void toggleSaveToGallery() {
    saveToGallery = !saveToGallery;
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putBoolean("save_gallery", saveToGallery);
    editor.commit();
    checkSaveToGalleryFiles();
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:9,代碼來源:MediaController.java

示例15: resetLocationCoordinates

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * Resets the location coordinates stores in SharedPreferences.
 *
 * @param context Context used to get the SharedPreferences
 */
public static void resetLocationCoordinates(Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sp.edit();

    editor.remove(PREF_COORD_LAT);
    editor.remove(PREF_COORD_LONG);
    editor.apply();
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:14,代碼來源:SunshinePreferences.java


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