1. mmkV is similar to SharedPreferences, but the storage and reading efficiency is better than that of sp. The
disadvantage is that mmkv has a larger dependency volume.
Simple use:
1. Add dependency in gradle
//mmkv
implementation 'com.tencent:mmkv-static:1.2.7'
2. Initialize in application
// Use steps
@Override
public void onCreate() {
super.onCreate();
application = this;
//retrofit网络请求框架
RetrofitHelper.getInstance().init(application);
MMKV.initialize(this);
}
3. Open in the class used:
全局变量:
MMKV mmkv = MMKV.defaultMMKV();//开启MMKV
4. Store data (key-value pair storage, can store any type)
//增加主页次数
mmkv.putInt("sumSlideCount", getSumCount() + 1);
5.Get data (value by key of map)
private volatile int homeSlideCount = mmkv.getInt("homeSlideCount", 0);