sharedpreferences存储位置,preferences窗口
[java]
import java.util.List;
import java.util.Map;
import android.content.Context;
import Android.content.shared preferences;
//*
publicclasssharepreferenceutil {
privatefinalstringmak=' inno view ';
privatefinalintmode=context.mode _ world _ readable context.mode _ world _ writeable;
privatefinalsharedpreferencessharedpreferences;
publicsharepreferenceutil (上下文上下文,字符串文件名称) {
shared preferences=context.getsharedpreferences (filename,MODE );
}
publicbooleansavesharedpreferences (string key,String value )。
shared preferences.editor editor=shared preferences.edit (;
try {
editor.putstring(key,AESencryptor.encrypt ) mak,value );
}catch(exceptione ) {
editor.putstring(key,value );
e .打印任务跟踪(;
}
return editor.commit (;
}
publicstringloadstringsharedpreference (string key ) {
String str=null;
try {
if(str!=空! ' '.equals(str ) }{
}
}catch(exceptione ) {
e .打印任务跟踪(;
}
return str;
}
publicbooleansavesharedpreferences {
shared preferences.editor editor=shared preferences.edit (;
editor.putint(key,value );
return editor.commit (;
}
publicintloadintsharedpreference {
returnsharedpreferences.getint (key,0 );
}
publicbooleansavesharedpreferences {
shared preferences.editor editor=shared preferences.edit (;
editor.putfloat(key,value );
return editor.commit (;
}
publicfloatloadfloatsharedpreference {
returnsharedpreferences.getfloat (key,牢固的豆芽);
}
publicbooleansavesharedpreferences (string key,Long value )。
shared preferences.editor editor=shared preferences.edit (;
editor.putlong(key,value );
return editor.commit (;
}
publiclongloadlongsharedpreference (string key ) (
returnsharedpreferences.getlong (key,zxdzxc;
}
publicbooleansavesharedpreferences (string key,Boolean value ) {
shared preferences.editor editor=shared preferences.edit (;
editor.putboolean(key,value );
return editor.commit (;
}
publicbooleanloadbooleansharedpreference {
returnsharedpreferences.get boolean (key,false );
}
publicbooleansaveallsharepreference {
int size=list.size (;
if(size1) {
返回假;
}
shared preferences.editor editor=shared preferences.edit (;
if(list.get(0)实例of string ) {
for(intI=0; i size; I ) {
editor.putString(keynameI,(string ) list.get(i ) I );
}
}elseif(list.get(0) instanceof Long ) )
for(intI=0; i size; I ) {
editor.putLong(keynameI,(long ) list.get(i ) I );
}
}elseif(list.get(0) instanceof Float ) )
for(intI=0; i size; I ) {
editor.putFloat(keynameI,(float ) list.get(i ) I );
}
}elseif(list.get(0) instanceof Integer ) )
for(intI=0; i size; I ) {
editor.putlong(keynameI,(Integer ) list.get(i ) I );
}
}elseif(list.get(0) instanceof Boolean ) )
for(intI=0; i size; I ) {
editor.putBoolean(keynameI,) boolean ) list.get(i ) I );
}
}
return editor.commit (;
}
publicmaploadallsharepreference {
return sharedpreferences.getAll (;
}
publicbooleanremovekey (字符串密钥) {
shared preferences.editor editor=shared preferences.edit (;
editor.remove(key;
return editor.commit (;
}
公共布尔远程全部密钥
shared preferences.editor editor=shared preferences.edit (;
editor.clear (;
return editor.commit (;
}
}