Java Code Examples for android.content.SharedPreferences.Editor#apply()
The following examples show how to use
android.content.SharedPreferences.Editor#apply() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FloatWinService.java From SoloPi with Apache License 2.0 | 6 votes |
@Override public void onDestroy() { // 清理定时任务 mInjectorService.unregister(this.provider); this.provider = null; stopForeground(true); LogUtil.w(TAG, "FloatWin onDestroy"); writeFileData(fileName, "destroy recording:" + new Date()); div = 0; // wm.removeView(view); //InjectorService.getInstance().stopInjection(); SharedPreferences sharedPreferences = getSharedPreferences("config", Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putString("state", "stop"); editor.apply(); // 取消注册广播 super.onDestroy(); }
Example 2
Source File: EventPreferencesNFC.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
void loadSharedPreferences(SharedPreferences preferences) { Editor editor = preferences.edit(); editor.putBoolean(PREF_EVENT_NFC_ENABLED, _enabled); editor.putString(PREF_EVENT_NFC_NFC_TAGS, _nfcTags); editor.putBoolean(PREF_EVENT_NFC_PERMANENT_RUN, this._permanentRun); editor.putString(PREF_EVENT_NFC_DURATION, String.valueOf(this._duration)); editor.apply(); }
Example 3
Source File: CommonUtils.java From product-emm with Apache License 2.0 | 5 votes |
/** * Clear client credentials. * @param context - Application context. */ public static void clearClientCredentials(Context context) { SharedPreferences mainPref = context.getSharedPreferences(Constants.PACKAGE_NAME, Context.MODE_PRIVATE); Editor editor = mainPref.edit(); editor.putString(Constants.CLIENT_ID, null); editor.putString(Constants.CLIENT_SECRET, null); editor.apply(); }
Example 4
Source File: SPHelper.java From JianDanRxJava with Apache License 2.0 | 5 votes |
public static void setString(String key, String value) { SharedPreferences sp = mContext.getSharedPreferences( SHARED_PREFERANCE_NAME, Context.MODE_PRIVATE); Editor editor = sp.edit(); editor.putString(key, value); editor.apply(); }
Example 5
Source File: PreferenceHelper.java From Common with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.GINGERBREAD) 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(); }
Example 6
Source File: PreferenceHelper.java From Common with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public static void write(Context context, String fileName, String k, int v) { SharedPreferences preference = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); Editor editor = preference.edit(); editor.putInt(k, v); editor.apply(); }
Example 7
Source File: PreferenceHelper.java From Common with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public static void remove(Context context, String fileName, String k) { SharedPreferences preference = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); Editor editor = preference.edit(); editor.remove(k); editor.apply(); }
Example 8
Source File: PreferenceUtils.java From BmapLite with GNU General Public License v3.0 | 4 votes |
public void setFloatPreference(String key, float value) { Editor ed = preference.edit(); ed.putFloat(key, value); ed.apply(); }
Example 9
Source File: SimpleSharedPreference.java From VideoMeeting with Apache License 2.0 | 4 votes |
public void remove(String key) { Editor editor = mPref.edit(); editor.remove(key); editor.apply(); }
Example 10
Source File: Api9Adapter.java From mytracks with Apache License 2.0 | 4 votes |
@Override public void applyPreferenceChanges(Editor editor) { // Apply asynchronously editor.apply(); }
Example 11
Source File: PreferenceUtil.java From RetroMusicPlayer with GNU General Public License v3.0 | 4 votes |
public void setLastPage(final int value) { final Editor editor = mPreferences.edit(); editor.putInt(LAST_PAGE, value); editor.apply(); }
Example 12
Source File: k.java From stynico with MIT License | 4 votes |
public static void a(Context context, String str, boolean z) { Editor edit = a(context).edit(); edit.putBoolean(str, z); edit.apply(); }
Example 13
Source File: Event.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
public void loadSharedPreferences(SharedPreferences preferences) { Editor editor = preferences.edit(); editor.putLong(PREF_EVENT_ID, this._id); editor.putString(PREF_EVENT_NAME, this._name); editor.putString(PREF_EVENT_PROFILE_START, Long.toString(this._fkProfileStart)); editor.putString(PREF_EVENT_PROFILE_END, Long.toString(this._fkProfileEnd)); editor.putBoolean(PREF_EVENT_ENABLED, this._status != ESTATUS_STOP); editor.putString(PREF_EVENT_NOTIFICATION_SOUND_START, this._notificationSoundStart); editor.putBoolean(PREF_EVENT_NOTIFICATION_VIBRATE_START, this._notificationVibrateStart); editor.putBoolean(PREF_EVENT_NOTIFICATION_REPEAT_START, this._repeatNotificationStart); editor.putString(PREF_EVENT_NOTIFICATION_REPEAT_INTERVAL_START, String.valueOf(this._repeatNotificationIntervalStart)); editor.putString(PREF_EVENT_NOTIFICATION_SOUND_END, this._notificationSoundEnd); editor.putBoolean(PREF_EVENT_NOTIFICATION_VIBRATE_END, this._notificationVibrateEnd); editor.putBoolean(PREF_EVENT_FORCE_RUN, this._forceRun); //editor.putBoolean(PREF_EVENT_UNDONE_PROFILE, this._undoneProfile); editor.putString(PREF_EVENT_PRIORITY_APP_SETTINGS, Integer.toString(this._priority)); editor.putString(PREF_EVENT_PRIORITY, Integer.toString(this._priority)); editor.putString(PREF_EVENT_DELAY_START, Integer.toString(this._delayStart)); editor.putString(PREF_EVENT_AT_END_DO, Integer.toString(this._atEndDo)); editor.putBoolean(PREF_EVENT_MANUAL_PROFILE_ACTIVATION, this._manualProfileActivation); editor.putString(PREF_EVENT_START_WHEN_ACTIVATED_PROFILE, this._startWhenActivatedProfile); editor.putString(PREF_EVENT_DELAY_END, Integer.toString(this._delayEnd)); editor.putBoolean(PREF_EVENT_NO_PAUSE_BY_MANUAL_ACTIVATION, this._noPauseByManualActivation); this._eventPreferencesTime.loadSharedPreferences(preferences); this._eventPreferencesBattery.loadSharedPreferences(preferences); this._eventPreferencesCall.loadSharedPreferences(preferences); this._eventPreferencesPeripherals.loadSharedPreferences(preferences); this._eventPreferencesCalendar.loadSharedPreferences(preferences); this._eventPreferencesWifi.loadSharedPreferences(preferences); this._eventPreferencesScreen.loadSharedPreferences(preferences); this._eventPreferencesBluetooth.loadSharedPreferences(preferences); this._eventPreferencesSMS.loadSharedPreferences(preferences); this._eventPreferencesNotification.loadSharedPreferences(preferences); this._eventPreferencesApplication.loadSharedPreferences(preferences); this._eventPreferencesLocation.loadSharedPreferences(preferences); this._eventPreferencesOrientation.loadSharedPreferences(preferences); this._eventPreferencesMobileCells.loadSharedPreferences(preferences); this._eventPreferencesNFC.loadSharedPreferences(preferences); this._eventPreferencesRadioSwitch.loadSharedPreferences(preferences); this._eventPreferencesAlarmClock.loadSharedPreferences(preferences); this._eventPreferencesDeviceBoot.loadSharedPreferences(preferences); editor.apply(); }
Example 14
Source File: PreferenceUtil.java From RetroMusicPlayer with GNU General Public License v3.0 | 4 votes |
public void setSongSortOrder(String sortOrder) { Editor edit = this.mPreferences.edit(); edit.putString(SONG_SORT_ORDER, sortOrder); edit.apply(); }
Example 15
Source File: PreferenceUtil.java From RetroMusicPlayer with GNU General Public License v3.0 | 4 votes |
public void setClassicNotification(final boolean value) { final Editor editor = mPreferences.edit(); editor.putBoolean(CLASSIC_NOTIFICATION, value); editor.apply(); }
Example 16
Source File: kbili.java From styT with Apache License 2.0 | 4 votes |
public static void a(Context context, String str, int i) { Editor edit = a(context).edit(); edit.putInt(str, i); edit.apply(); }
Example 17
Source File: ServiceManager.java From androidpn-client with Apache License 2.0 | 4 votes |
public void setSettings() { // apiKey = getMetaDataValue("ANDROIDPN_API_KEY"); // Log.i(LOGTAG, "apiKey=" + apiKey); // // if (apiKey == null) { // // Log.e(LOGTAG, "Please set the androidpn api key in the manifest file."); // // throw new RuntimeException(); // // } SharedPreferences mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); apiKey = mySharedPreferences.getString("prefApikey", "1234567890").trim(); xmppHost = mySharedPreferences.getString("prefXmpphost", "192.168.0.1").trim(); xmppPort = mySharedPreferences.getString("prefXmppport", "5222").trim(); email = mySharedPreferences.getString("prefEmail", "").trim(); pass = mySharedPreferences.getString("prefPass", "").trim(); user = mySharedPreferences.getString("prefUser", "").trim(); name = mySharedPreferences.getString("prefName", "").trim(); boolean prefNtfy = mySharedPreferences.getBoolean("prefNtfy",true); boolean prefSound = mySharedPreferences.getBoolean("prefSound",true); boolean prefVibrate = mySharedPreferences.getBoolean("prefVibrate",true); boolean prefToast = mySharedPreferences.getBoolean("prefToast",false); Log.i(LOGTAG, "apiKey=" + apiKey); Log.i(LOGTAG, "xmppHost=" + xmppHost); Log.i(LOGTAG, "xmppPort=" + xmppPort); Log.i(LOGTAG, "user=" + user); Log.i(LOGTAG, "name=" + name); Log.i(LOGTAG, "email=" + email); sharedPrefs = context.getSharedPreferences( Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); Editor editor = sharedPrefs.edit(); editor.putString(Constants.API_KEY, apiKey); editor.putString(Constants.VERSION, version); editor.putString(Constants.XMPP_HOST, xmppHost); editor.putString(Constants.XMPP_USERNAME, user); editor.putString(Constants.XMPP_PASSWORD, pass); editor.putString(Constants.XMPP_EMAIL, email); editor.putString(Constants.NAME, name); try { editor.remove(Constants.SETTINGS_NOTIFICATION_ENABLED); editor.remove(Constants.SETTINGS_SOUND_ENABLED); editor.remove(Constants.SETTINGS_VIBRATE_ENABLED); editor.remove(Constants.SETTINGS_TOAST_ENABLED); } catch (Exception e) { Log.d(LOGTAG, "Settings not removed"); } editor.putBoolean(Constants.SETTINGS_NOTIFICATION_ENABLED, prefNtfy); editor.putBoolean(Constants.SETTINGS_SOUND_ENABLED, prefSound); editor.putBoolean(Constants.SETTINGS_VIBRATE_ENABLED, prefVibrate); editor.putBoolean(Constants.SETTINGS_TOAST_ENABLED, prefToast); editor.putInt(Constants.XMPP_PORT, Integer.parseInt(xmppPort.trim())); editor.putString(Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, callbackActivityPackageName); editor.putString(Constants.CALLBACK_ACTIVITY_CLASS_NAME, callbackActivityClassName); editor.apply(); // Log.i(LOGTAG, "sharedPrefs=" + sharedPrefs.toString()); }
Example 18
Source File: f.java From letv with Apache License 2.0 | 4 votes |
protected static void a(String str, long j) { Editor edit = a.edit(); edit.putLong(str, j); edit.apply(); }
Example 19
Source File: SpUtil.java From styT with Apache License 2.0 | 3 votes |
/** * 保存long值 * * @param context 上下文 * @param key 键 * @param value 值 */ public static void putLong(Context context, String key, long value) { SharedPreferences sp = getSp(context); Editor editor = sp.edit(); editor.putLong(key, value); editor.apply(); }
Example 20
Source File: ConfigUtil.java From ONE-Unofficial with Apache License 2.0 | 2 votes |
/** * 写boolean配置到本地 * @param file 存储的文件名 * @param key key * @param value 结果 */ public static void writeBoolean(String file, String key, boolean value) { Editor editor = context.getSharedPreferences(file, Context.MODE_PRIVATE).edit(); editor.putBoolean(key, value); editor.apply(); }