自己项目中的使用的一个库,整理一下分享给大家
已经上传了github,欢迎大家start
用法
jitpack用起来比较方便
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.evernightking:Storage:v1.0'
}
集成一个application ,在onCreate()方法中去初始化一下
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Store.init(this,"testFile");
}
}
第二个参数是保存本地的文件名
Store.put("zhangsan", new TestBean());
Store.put("string", "string");
Store.put("int", 100);
Store.put("long", 100L);
Store.put("byte", (byte) 100);
Store.put("short", (short) 100);
Store.put("float", (float) 100);
Store.put("boolean", true);
ArrayList<TestBean> list = new ArrayList<>();
list.add(new TestBean());
list.add(new TestBean());
list.add(new TestBean());
Store.put("listsss", list);
ArrayList<TestBean> listsss = Store.get("listsss", ArrayList.class, null);
TestBean testBean = listsss.get(1);
String s = Store.get("zhangsan", TestBean.class, null).toString() + "\n" +
Store.get("string", "") + "\n"
+ Store.get("int", 0) + "\n" +
Store.get("long", 0L) + "\n" +
Store.get("byte", (byte) 0) + "\n"
+ Store.get("short", (short) 0) + "\n" +
Store.get("float", (float) 0) + "\n" +
Store.get("boolean", true) + "\n"
+ "\n" + testBean.toString();
用base64简单加密了一下,使用还是很方便的,数据文件保存在data/data/包名/files/storage/文件夹中
代码很简单,就几个类,感兴趣的自己看一下吧