Code example for SharedPreferences.Editor: Saving app preferences

Methods: commit, putInt, putLong

0
		} 
 
		Editor editor = mPreferences.edit();
 
		int totalLaunchCount = mPreferences.getInt(PREF.TOTAL_LAUNCH_COUNT, 0) + 1;
		editor.putInt(PREF.TOTAL_LAUNCH_COUNT, totalLaunchCount);
 
		long currentMillis = System.currentTimeMillis();
 
		long timeOfAbsoluteFirstLaunch = mPreferences.getLong(
				PREF.TIME_OF_ABSOLUTE_FIRST_LAUNCH, 0);
		if (timeOfAbsoluteFirstLaunch == 0) {
			// this is the first launch! 
			timeOfAbsoluteFirstLaunch = currentMillis;
			editor.putLong(PREF.TIME_OF_ABSOLUTE_FIRST_LAUNCH,
					timeOfAbsoluteFirstLaunch);
		} 
 
		long timeOfLastPrompt = mPreferences.getLong(PREF.TIME_OF_LAST_PROMPT,
				0); 
 
		int launchesSinceLastPrompt = mPreferences.getInt(
				PREF.LAUNCHES_SINCE_LAST_PROMPT, 0) + 1;
		editor.putInt(PREF.LAUNCHES_SINCE_LAST_PROMPT, launchesSinceLastPrompt);
 
		if (totalLaunchCount >= mMinLaunchesUntilInitialPrompt
				&& ((currentMillis - timeOfAbsoluteFirstLaunch)) >= (mMinDaysUntilInitialPrompt * DateUtils.DAY_IN_MILLIS)) {
			// requirements for initial launch are met 
			if (timeOfLastPrompt == 0 /* user was not yet shown a prompt */
					|| (launchesSinceLastPrompt >= mMinLaunchesUntilNextPrompt && ((currentMillis - timeOfLastPrompt) >= (mMinDaysUntilNextPrompt * DateUtils.DAY_IN_MILLIS)))) {
				editor.putLong(PREF.TIME_OF_LAST_PROMPT, currentMillis);
				editor.putInt(PREF.LAUNCHES_SINCE_LAST_PROMPT, 0);
				editor.commit();
				showDialog(); 
			} else { 
				editor.commit();
			} 
		} else { 
			editor.commit();
		} 
 
	} 
 
	@Override 
Connect your IDE to all the code out there  Get Codota for Java