Applies the editor changes if running on a build version where this method is available, else commits the changes. - Android App

Android examples for App:App Running

Description

Applies the editor changes if running on a build version where this method is available, else commits the changes.

Demo Code


//package com.java2s;

import android.content.SharedPreferences;
import android.os.Build;

public class Main {
    /**//from w w w  .j a  va2  s .c  om
     * 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