Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Android】1.3.3版本多进程初始化,导致数据丢失 #1245

Closed
pinguo-hedongjin opened this issue Mar 11, 2024 · 5 comments
Closed

Comments

@pinguo-hedongjin
Copy link

pinguo-hedongjin commented Mar 11, 2024

1、初始化代码
override fun onCreate() {
super.onCreate()

    if (isMainProcess) {
        MMKV.initialize(context) { ReLinker.loadLibrary(context, it) }
        MMKV.registerHandler(object : MMKVHandler {
            o

            override fun mmkvLog(
                level: MMKVLogLevel?,
                file: String?,
                line: Int,
                func: String?,
                message: String?
            ) {
                val log = "<$file" + ":" + line + "::" + func + "> " + R.id.message
                when (level) {
                    MMKVLogLevel.LevelDebug -> logd("MMKVHelper", log)
                    MMKVLogLevel.LevelInfo -> logi("MMKVHelper", log)
                    MMKVLogLevel.LevelWarning -> logw("MMKVHelper", log)
                    MMKVLogLevel.LevelError -> loge("MMKVHelper", log)
                    else -> logv("MMKVHelper", log)
                }
            }
        })
    } else if (isPushProcess) {
        MMKV.initialize(context) { ReLinker.loadLibrary(context, it) }
        MMKV.registerHandler(object : MMKVHandler {
            override fun mmkvLog(
                level: MMKVLogLevel?,
                file: String?,
                line: Int,
                func: String?,
                message: String?
            ) {
                val log = "<$file" + ":" + line + "::" + func + "> " + R.id.message
                when (level) {
                    MMKVLogLevel.LevelDebug -> logd("MMKVHelper", log)
                    MMKVLogLevel.LevelInfo -> logi("MMKVHelper", log)
                    MMKVLogLevel.LevelWarning -> logw("MMKVHelper", log)
                    MMKVLogLevel.LevelError -> loge("MMKVHelper", log)
                    else -> logv("MMKVHelper", log)
                }
            }
        })
    }
}

2、日志打印
截屏2024-03-11 16 58 04

问题:
多进程初始化后,之前保存的数据丢失

@lingol
Copy link
Collaborator

lingol commented Mar 11, 2024

Your so-called log doesn't print anything valuable. It's impossible to do any further investigation.
Check your log printing code again.

@pinguo-hedongjin
Copy link
Author

What further information do we need to provide?

@lingol
Copy link
Collaborator

lingol commented Mar 13, 2024

Your so-called log doesn't print anything valuable. It's impossible to do any further investigation. Check your log printing code again.

These.

@pinguo-hedongjin
Copy link
Author

I found that the same mmapID has multi-process access, but it is still declared in SINGLE_PROCESS_MODE mode, and there is currently a problem that the data that has been written to disk before cannot be read after restarting;
Is this as expected?

@lingol
Copy link
Collaborator

lingol commented Mar 18, 2024

Definitly. It must be open in MULTI_PROCESS_MODE.

@lingol lingol closed this as completed Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants