set key value pair to SharedPreferences - Android Android OS

Android examples for Android OS:SharedPreferences

Description

set key value pair to SharedPreferences

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class Main {
    private static final String REDU_PIN_CODE = "REDU_PIN_CODE";

    public static boolean set(Context context, String pinCode) {
        return getPrefs(context).edit().putString(REDU_PIN_CODE, pinCode)
                .commit();/*w  w  w  . j a  v a2 s. c om*/
    }

    private static SharedPreferences getPrefs(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context);
    }
}

Related Tutorials