put boolean preferences - Android android.content

Android examples for android.content:SharedPreferences

Description

put boolean preferences

Demo Code

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;
import java.io.*;

public class Main{

    /**/* w w w . jav  a2  s. c  o  m*/
     * put boolean preferences
     *
     * @param context
     * @param key The name of the preference to modify
     * @param value The new value for the preference
     * @return True if the new values were successfully written to persistent storage.
     */
    public static boolean putBoolean(Context context, String key,
            boolean value) {
        SharedPreferences settings = context.getSharedPreferences(
                PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(key, value);
        return editor.commit();
    }

}

Related Tutorials