read String from SharedPreferences - Android Android OS

Android examples for Android OS:SharedPreferences

Description

read String from SharedPreferences

Demo Code


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

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

    public static String readString(Context context, String key,
            String defValue) {//from w  w  w  .  j a  v a 2  s.co  m
        return getPreferences(context).getString(key, defValue);
    }

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

Related Tutorials