本文整理汇总了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);
}
示例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();
}
示例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.
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}
示例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();
}
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}