当前位置: 首页>>代码示例>>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;未经允许,请勿转载。