阅读 60

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 (;

}

}


文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐