MMKV使用

dependencies {
    implementation 'com.tencent:mmkv:1.0.15'
    // replace "1.0.15" with any available version
}

初始化:

Application里面初始化:
 MMKV.initialize(this)
//……一个全局的实例
// MMKV kv = MMKV.defaultMMKV();

 MMKV mMkv = MMKV.mmkvWithID(Constant.MMKV_PREFERENCES, MMKV.SINGLE_PROCESS_MODE);
// 存储数据:
mMkv.encode("Stingid", "123456");
mMkv.encode("bool", true);
mMkv.encode("int", Integer.MIN_VALUE);

// 取数据:
String id=mMkv.decodeString("id", null);
boolean bValue = mMkv.decodeBool("bool");
int iValue = kv.decodeInt("int");
// 移除数据:
 mMkv.remove("Stingid");
 mMkv.remove("bool");
 mMkv.remove("int");

你可能感兴趣的:(MMKV使用)