Can be combined with Gson to convert the JavaBean into a string implementation of the object access, the basic code is as follows
PackageCom.example.luozhenlonghp.project_aidl_demo;
ImportAndroid.content.Context;
ImportAndroid.content.SharedPreferences;
/**
* Use for Save data ofstring,int,boolean,list<anybean>
* Created by LUOZHENLONGHP on 2017/5/13.
*/
Public classsputils {
/**
*
* @param Context
* @param FileName
* @param Key
* @param Value
*/
Public static voidPutstring (Context context,stringfilename,string key,string value) {
Sharedpreferences sp = context.getsharedpreferences (filename,context.mode_private);
Sharedpreferences.editor edit =sp.edit ();
Edit.putstring (Key,value);
Edit.commit ();
}
/**
*
* @param Context
* @param FileName
* @param Key
* @return Ifget failed return "";
*/
Public StaticString getString (Context context,string filename,string key) {
Sharedpreferences sp =context.getsharedpreferences (fileName, context.mode_private);
String result = sp.getstring (key,"");
returnResult
}
Public static voidPutint (Context context,string filename,string Key,intValue) {
Sharedpreferences sp =context.getsharedpreferences (fileName, context.mode_private);
Sharedpreferences.editor edit =sp.edit ();
Edit.putint (Key,value);
Edit.commit ();
}
public static intGetInt (Context context,string filename,string key) {
Sharedpreferences sp =context.getsharedpreferences (fileName, context.mode_private);
intresult = Sp.getint (key, 0);
returnResult
}
Public static voidPutboolean (Context context,string filename,string Key,BooleanValue) {
Sharedpreferences sp =context.getsharedpreferences (fileName, context.mode_private);
Sharedpreferences.editor edit =sp.edit ();
Edit.putboolean (Key,value);
Edit.commit ();
}
Public StaticbooleanGetboolean (Context context,string filename,string key) {
Sharedpreferences sp =context.getsharedpreferences (fileName, context.mode_private);
Booleanresult = Sp.getboolean (key,false);
returnResult
}
}
Sputils, Access simple strings, Int,boolean and JavaBean objects