Java Code Examples for com.tencent.mmkv.MMKV#defaultMMKV()

The following examples show how to use com.tencent.mmkv.MMKV#defaultMMKV() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MMKVUtils.java    From TemplateAppProject with Apache License 2.0 4 votes vote down vote up
public static MMKV getsMMKV() {
    if (sMMKV == null) {
        sMMKV = MMKV.defaultMMKV();
    }
    return sMMKV;
}
 
Example 2
Source File: MainActivity.java    From DevUtils with Apache License 2.0 4 votes vote down vote up
/**
 * MMKV 简单使用
 */
private void mmkvSimple() {
    MMKV defaultMMKV = MMKV.defaultMMKV();

    String mmapID = defaultMMKV.mmapID();

    defaultMMKV.putString(KeyConstants.Common.KEY_DATA, "defaultMMKV 存储数据");
    String data = defaultMMKV.getString(KeyConstants.Common.KEY_DATA, null);

    MMKV tempMMKV = MMKV.mmkvWithID("temp");
    String tempData = tempMMKV.getString(KeyConstants.Common.KEY_DATA, null);

    MMKV mmapIDMMKV = MMKV.mmkvWithID(mmapID);
    String mmapIdData = mmapIDMMKV.getString(KeyConstants.Common.KEY_DATA, null);

    StringBuilder builder = new StringBuilder();
    builder.append("default MMKV")
            .append(StringUtils.NEW_LINE_STR)
            .append("\t\tmmapID: " + mmapID)
            .append(StringUtils.NEW_LINE_STR)
            .append("\t\tdata: " + data);

    builder.append(StringUtils.NEW_LINE_STR)
            .append(StringUtils.NEW_LINE_STR);

    builder.append("temp MMKV")
            .append(StringUtils.NEW_LINE_STR)
            .append("\t\tmmapID: " + tempMMKV.mmapID())
            .append(StringUtils.NEW_LINE_STR)
            .append("\t\tdata: " + tempData);

    builder.append(StringUtils.NEW_LINE_STR)
            .append(StringUtils.NEW_LINE_STR);

    builder.append("mmapID MMKV")
            .append(StringUtils.NEW_LINE_STR)
            .append("\t\tmmapID: " + mmapIDMMKV.mmapID())
            .append(StringUtils.NEW_LINE_STR)
            .append("\t\tdata: " + mmapIdData);

    DevLogger.dTag(mTag, builder.toString());
}
 
Example 3
Source File: MMKVUtils.java    From TemplateAppProject with Apache License 2.0 2 votes vote down vote up
/**
 * 初始化
 *
 * @param context
 */
public static void init(Context context) {
    MMKV.initialize(context.getApplicationContext());
    sMMKV = MMKV.defaultMMKV();
}