write String to SharedPreferences - Android Android OS

Android examples for Android OS:SharedPreferences

Description

write String to SharedPreferences

Demo Code


//package com.book2s;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class Main {
    public static final String PREF_NAME = "FILTER_PREFERENCES";
    public static final int MODE = Context.MODE_PRIVATE;

    public static void writeString(Context context, String key, String value) {
        getEditor(context).putString(key, value).commit();

    }// w ww  .j ava2  s .co m

    public static Editor getEditor(Context context) {
        return getPreferences(context).edit();
    }

    public static SharedPreferences getPreferences(Context context) {
        return context.getSharedPreferences(PREF_NAME, MODE);
    }
}

Related Tutorials