Code example for SharedPreferences.Editor: Saving app preferences

Methods: clear, commit

0
 
    /* Clear up the preferences for tests*/ 
    public void clearPreferences() { 
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mTargetContext);
        Editor editor = settings.edit();
        editor.clear();
        editor.commit(); 
    } 
 
    // Mark the preference that it is not the first time to use the app. 
    public void markNotFirstTime() { 
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mTargetContext);
        Editor editor = settings.edit();
        editor.putBoolean(AMPrefKeys.FIRST_TIME_KEY, true);
        editor.putString(AMPrefKeys.SAVED_VERSION_KEY, mTestContext.getString(R.string.app_version));
        editor.commit();
    } 
}