Code example for SharedPreferences.Editor: Saving app preferences

Methods: clear, commit

1
	 * @param context 
	 */ 
	public static void clear(Context context){
	    SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
	    Editor editor = pref.edit();
	    editor.clear();
	    editor.commit();
	} 
 
	/** 
	 * 从SharedPreferences读取accessstoken 
	 * @param context 
	 * @return Oauth2AccessToken 
	 */ 
	public static Oauth2AccessToken readAccessToken(Context context){
		Oauth2AccessToken token = new Oauth2AccessToken();
		SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
		token.setToken(pref.getString("token", ""));
		token.setExpiresTime(pref.getLong("expiresTime", 0));
		return token;
	}