package com.example.text_month01.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
public class SharedPrefaredUtil {
private static final String name="config";
public static void saveValue(Context context,String key,Object value){
SharedPreferences sp = context.getSharedPreferences(name, Context.MODE_PRIVATE);
Editor edit = sp.edit();
String type = value.getClass().getSimpleName();
if ("Boolean".equals(type)) {
edit.putBoolean(key, (Boolean)value);
}
edit.commit();
}
public static Object getvalue(Context context,String key,Object value){
SharedPreferences sp = context.getSharedPreferences(name, Context.MODE_PRIVATE);
String type = value.getClass().getSimpleName();
if ("Boolean".equals(type)) {
return sp.getBoolean(key, false);
}
return null;
}
}
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
public class SharedPrefaredUtil {
private static final String name="config";
public static void saveValue(Context context,String key,Object value){
SharedPreferences sp = context.getSharedPreferences(name, Context.MODE_PRIVATE);
Editor edit = sp.edit();
String type = value.getClass().getSimpleName();
if ("Boolean".equals(type)) {
edit.putBoolean(key, (Boolean)value);
}
edit.commit();
}
public static Object getvalue(Context context,String key,Object value){
SharedPreferences sp = context.getSharedPreferences(name, Context.MODE_PRIVATE);
String type = value.getClass().getSimpleName();
if ("Boolean".equals(type)) {
return sp.getBoolean(key, false);
}
return null;
}
}