KObjectSave是用来代替androidSharedPreferences的键值存储方式,支持几乎所有类型(int,string,Date,bool,List等),它可以方便的存储应用的设置选项,用户的点击记录等。
添加依赖在app的build.gradle中添加
dependencies { compile 'cn.ikaze.KObjectSave:library:1.0.0'}使用首先要有一个基础的类用于存储
public class Student { int no = 1; //default 1 String name = "gojuukaze";//default gojuukaze Date birthday = new Date(); //default now List subjects; public String toString() { Format format = new SimpleDateFormat("yyyy-MM-dd"); String birthdayString = format.format(birthday); return "No." + no + ", name: " + name + ", birthday: " + birthdayString + ", subjects: " + subjects; }}使用 KObjectSave 存储Student
KObjectSave kSave = new KObjectSave(this, Student.class);Student st = (Student) kSave.getObj();st.no=23;st.name="A";st.subjects=new ArrayList(){{add("math");add("physics");}};try { kSave.save(st);} catch (IOException | IllegalAccessException e) { e.printStackTrace();}加载
Student tempSt = (Student) new KObjectSave(this, Student.class).getObj();lod.d("KObjectSave",""+tempSt);例子Example
bintray地址Here
注意!!数据没有加密,不要用户存储用户密码等隐私数据
评论