张冉
zhangran 1 year ago
parent 6bc2a30790
commit eb25df3375

@ -5,39 +5,68 @@ import android.content.Context;
import android.content.SharedPreferences;
/**
* 使SP
* ACache
* 使 Android SharedPreferences SP
*
*/
public class ACache {
/**
* SharedPreferences SharedPreferences Android
* 便
*
*/
private SharedPreferences preference;
private ACache(Context ctx){
preference = ctx.getSharedPreferences("ACache",0);
/**
* ACache Context Context SharedPreferences
* SharedPreferences "ACache" 0 MODE_PRIVATE访 SharedPreferences
*
* @param ctx Android Context SharedPreferences
*/
private ACache(Context ctx) {
preference = ctx.getSharedPreferences("ACache", 0);
}
/**
* ACache Context ACache
* 使便使
* @param ctx Android Context ACache 便
* @return ACache
*/
public static ACache get(Context ctx) {
return new ACache(ctx);
}
/**
* keyvalue SharedPreferences
* SharedPreferences Editor使
*
* @param key 便
* @param value HTML
*/
public void put(String key, String value) {
try{
try {
SharedPreferences.Editor editor = preference.edit();
editor.putString(key, value);
editor.commit();
}catch (Exception e){
} catch (Exception e) {
}
}
/**
* String
*
* @param key
* @return String
* key SharedPreferences
* null
*
* @param key 使便
* @return null
*/
public String getAsString(String key) {
try{
return preference.getString(key,null);
}catch (Exception e){
try {
return preference.getString(key, null);
} catch (Exception e) {
return null;
}
}
}
}
Loading…
Cancel
Save