commit Or Apply Shared Preferences Editor - Android android.content

Android examples for android.content:SharedPreferences

Description

commit Or Apply Shared Preferences Editor

Demo Code

import com.amazonaws.services.gamelift.model.Build;

import android.content.SharedPreferences;

public class Main {

  /**//  w w  w .ja v  a2  s .c o  m
   * Applies the editor changes if running on a build version where this method is
   * available, else commits the changes.
   * 
   * @param editor
   *          The editor which's changes are to be commited or applied.
   */
  public static final void commitOrApplySharedPreferencesEditor(SharedPreferences.Editor editor) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
      editor.apply();
    } else {
      editor.commit();
    }
  }

}

Related Tutorials