get Cache from SharedPreferences - Android Android OS

Android examples for Android OS:SharedPreferences

Description

get Cache from SharedPreferences

Demo Code


import android.content.Context;
import android.content.SharedPreferences;

public class Main{
    public static String getCache(Context context, String key,
            String defaultValue) {
        SharedPreferences sp = context.getSharedPreferences(
                TagsUtil.SHARED_PREFS_NAME, Context.MODE_PRIVATE);
        return sp.getString(key, defaultValue);
    }/*  ww w .ja  va 2 s. c om*/
    public static int getCache(Context context, String key, int defaultValue) {
        SharedPreferences sp = context.getSharedPreferences(
                TagsUtil.SHARED_PREFS_NAME, Context.MODE_PRIVATE);
        return sp.getInt(key, defaultValue);
    }
    public static boolean getCache(Context context, String key,
            boolean defaultValue) {
        SharedPreferences sp = context.getSharedPreferences(
                TagsUtil.SHARED_PREFS_NAME, Context.MODE_PRIVATE);
        return sp.getBoolean(key, defaultValue);
    }
}

Related Tutorials