demo:
https://github.com/anymyna/android-example-ant
步骤:
1、 初始化
dependencies {
implementation 'com.tencent:mmkv:1.2.6'
}
2、 用法
application 中初始化
String rootDir = MMKV.initialize(this);
Log.d("MMKVActivity","mmkv root: " + rootDir);
数据存取
MMKV kv = MMKV.defaultMMKV();
kv.encode("bool", true);
boolean bValue = kv.decodeBool("bool");
Log.d(TAG,"MMKVActivity bValue: " + bValue);
kv.encode("int", Integer.MIN_VALUE);
int iValue = kv.decodeInt("int");
Log.d(TAG,"MMKVActivity iValue: " + iValue);
kv.encode("string", "Hello from mmkv");
String str = kv.decodeString("string");
Log.d(TAG,"MMKVActivity str: " + str);
参考:
https://github.com/Tencent/MMKV/wiki/android_tutorial_cn