本文整理汇总了Java中android.content.SharedPreferences.Editor.apply方法的典型用法代码示例。如果您正苦于以下问题:Java Editor.apply方法的具体用法?Java Editor.apply怎么用?Java Editor.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.SharedPreferences.Editor
的用法示例。
在下文中一共展示了Editor.apply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setValue
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
/**
* Set value method
* @param context
* @param key
* @param value
* @param secure
* @throws NoSuchAlgorithmException
*/
private static void setValue(@NonNull Context context, @NonNull String key, @NonNull String value, @NonNull Boolean secure) throws NoSuchAlgorithmException {
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
Editor editor = settings.edit();
// Check if current Android version is Nougat or higher. If so, hash key and hash value, if needed.
// Otherwise, use the raw key and value due to limitations by previous Android versions. Albeit this is not ideal, it is not really insecure due the fact
// notes are encrypted by an unknown password provided by the user. Nevertheless, it is possible to see the current keys.
// TODO: create a way so keys are always encrypted.
if(isVersionNougatOrHigher()) {
key = EncryptionHandler.hashString(key);
value = secure ? EncryptionHandler.hashString(value) : value;
}
editor.putString(key, value);
editor.apply();
}
示例2: initRecord
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
private void initRecord(Context context) {
this.mPreferences = context.getSharedPreferences(DOWNLOAD_RECORD, 0);
this.recordMap = (Map) FastJsonUtils.fromJson(this.mPreferences.getString(CacheKey
.DOWNLOAD_RECORD, null), new TypeReference<Map<String, DownloadRecord>>() {
});
if (this.recordMap == null) {
String oldRecord = FileCache.get(context, DOWNLOAD_RECORD).getAsString(CacheKey
.DOWNLOAD_RECORD);
this.recordMap = (Map) FastJsonUtils.fromJson(oldRecord, new
TypeReference<Map<String, DownloadRecord>>() {
});
if (this.recordMap == null) {
this.recordMap = new HashMap();
return;
}
Editor editor = this.mPreferences.edit();
editor.putString(CacheKey.DOWNLOAD_RECORD, oldRecord);
editor.apply();
}
}
示例3: a
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
public void a(String str, boolean z) {
if (N() != null) {
Editor edit = N().edit();
edit.putBoolean(str, z);
edit.apply();
}
}
示例4: putStringProcess
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
public static void putStringProcess(String key, String value)
{
SharedPreferences sharedPreferences = HeroVideoApp.getInstance().getSharedPreferences("preference_mu", Context.MODE_MULTI_PROCESS);
Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.apply();
}
示例5: putInt
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
private static void putInt(String key, int value) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(
BilibiliApp.getInstance());
Editor editor = sharedPreferences.edit();
editor.putInt(key, value);
editor.apply();
}
示例6: clear
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
public static void clear(Context context, String fileName) {
SharedPreferences sp = SharedPreferencesImpl.getSharedPreferences(context, getFileName(fileName),
Context.MODE_PRIVATE);
Editor editor = sp.edit();
editor.clear();
editor.apply();
}
示例7: c
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
protected static void c(String str, String str2) {
if (a != null) {
Editor edit = a.edit();
edit.putString(str, str2);
edit.apply();
}
}
示例8: setIncludeDeviceInfoPreference
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
public static void setIncludeDeviceInfoPreference(Context context, boolean value) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
Editor editor = sharedPrefs.edit();
editor.putBoolean(context.getString(R.string.pref_include_device_info), value);
editor.apply();
}
示例9: putBoolean
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
public static void putBoolean(String key, boolean value) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(
BilibiliApp.getInstance());
Editor editor = sharedPreferences.edit();
editor.putBoolean(key, value);
editor.apply();
}
示例10: write
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
public static void write(Context context, String fileName, String k,
String v) {
SharedPreferences preference = context.getSharedPreferences(fileName,
Context.MODE_PRIVATE);
Editor editor = preference.edit();
editor.putString(k, v);
editor.apply();
}
示例11: setChangeLogSeen
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
private void setChangeLogSeen() throws NameNotFoundException {
Context context = shadowApplication.getApplicationContext();
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(
context.getPackageName(), 0);
Editor editor = PreferenceManager.getDefaultSharedPreferences(shadowApplication.getApplicationContext())
.edit();
editor.putInt("ckChangeLog_last_version_code", packageInfo.versionCode);
editor.apply();
}
示例12: a
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
public static void a(Context context, String str, int i) {
if (a(context)) {
b(context);
Editor edit = a.edit();
edit.putInt(str, i);
edit.apply();
return;
}
z.d();
}
示例13: setArtistDetailSongSortOrder
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
public void setArtistDetailSongSortOrder(String sortOrder) {
Editor edit = this.mPreferences.edit();
edit.putString(ARTIST_DETAIL_SONG_SORT_ORDER, sortOrder);
edit.apply();
}
示例14: setConntectedVpnProfileDisconnected
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
public static void setConntectedVpnProfileDisconnected(Context c) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
Editor prefsedit = prefs.edit();
prefsedit.putString(LAST_CONNECTED_PROFILE, null);
prefsedit.apply();
}
示例15: removePreference
import android.content.SharedPreferences.Editor; //导入方法依赖的package包/类
private static void removePreference(Context context, String prefKey) {
Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.remove(prefKey);
editor.apply();
}