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 - bool读取错误 #988

Closed
AtlantisFaded opened this issue Dec 16, 2022 · 13 comments
Closed

Android - bool读取错误 #988

AtlantisFaded opened this issue Dec 16, 2022 · 13 comments

Comments

@AtlantisFaded
Copy link

平台:Android

背景:隐私弹窗的功能,使用mmkv,bool标志

错误case描述:隐私弹窗弹出后,已经同意后,在已经设置为true的情况后,下一次启动依然读取到的默认值(false)

日志(对应下面的关键代码操作):
image

关键代码:

  1. 已经在application正确初始化:
    image
  2. 数值读取:
    image
  3. onCreate中判断:
    image
  4. 隐私弹窗点击同意后设置bool:
    image
@AtlantisFaded
Copy link
Author

implementation 'com.tencent:mmkv:1.2.14'

@AtlantisFaded
Copy link
Author

其他的bool都正确,唯独这个隐私弹窗的值错误,跟bool值无关,试过了int,依然不正确。
怀疑是跟启动时机有关,在onCreate()中读取不准,但是延迟5s后读取,依然不准,比较玄学了。。

@lingol
Copy link
Collaborator

lingol commented Dec 16, 2022

You should provide logs of MMKV.

@lingol
Copy link
Collaborator

lingol commented Dec 16, 2022

Most of the case, you could solve it by setting MULTI_PROCESS_MODE if haven't.
If that doesn't solve your problem, you could start a small demo project, add the privacy policy set/get logic and see if it still happens.

@AtlantisFaded
Copy link
Author

MMKV Log(中间分割线上面是初次启动并设置true,下面是第二次启动)

---------------------------- PROCESS STARTED (1398) for package com.atlantis.launcher ----------------------------
2022-12-16 20:18:47.389 1398-1398 MMKV com.atlantis.launcher I Enable checkProcessMode()
2022-12-16 20:18:47.393 1398-1398 MMKV com.atlantis.launcher I native-bridge.cpp:104::JNI_OnLoad current API level = 28, libc++_shared=0
2022-12-16 20:18:47.394 1398-1398 MMKV com.atlantis.launcher I MMKV.cpp:165::initialize version v1.2.14, page size 4096, arch arm64-v8a
2022-12-16 20:18:47.394 1398-1398 MMKV com.atlantis.launcher I MMKV.cpp:176::initialize armv8 AES instructions is supported
2022-12-16 20:18:47.394 1398-1398 MMKV com.atlantis.launcher I MMKV.cpp:184::initialize armv8 CRC32 instructions is supported
2022-12-16 20:18:47.394 1398-1398 MMKV com.atlantis.launcher I MMKV.cpp:207::initializeMMKV root dir: /data/user/0/com.atlantis.launcher/files/mmkv
2022-12-16 20:18:47.598 1398-1398 MMKV com.atlantis.launcher I MemoryFile.cpp:97::open open fd[0x59], /data/user/0/com.atlantis.launcher/files/mmkv/mmkv.default
2022-12-16 20:18:47.599 1398-1398 MMKV com.atlantis.launcher I MemoryFile.cpp:97::open open fd[0x5a], /data/user/0/com.atlantis.launcher/files/mmkv/mmkv.default.crc
2022-12-16 20:18:47.599 1398-1398 MMKV com.atlantis.launcher I <MMKV_IO.cpp:81::loadFromFile> loading [mmkv.default] with 0 actual size, file size 4096, InterProcess 0, meta info version:0
2022-12-16 20:18:47.599 1398-1398 MMKV com.atlantis.launcher I <MMKV_IO.cpp:130::loadFromFile> loaded [mmkv.default] with 0 key-values
2022-12-16 20:18:47.624 1398-1398 MMKV com.atlantis.launcher I MemoryFile.cpp:97::open open fd[0x5b], /data/user/0/com.atlantis.launcher/files/mmkv/UserConfig
2022-12-16 20:18:47.624 1398-1398 MMKV com.atlantis.launcher I MemoryFile.cpp:97::open open fd[0x5c], /data/user/0/com.atlantis.launcher/files/mmkv/UserConfig.crc
2022-12-16 20:18:47.624 1398-1398 MMKV com.atlantis.launcher I <MMKV_IO.cpp:81::loadFromFile> loading [UserConfig] with 0 actual size, file size 4096, InterProcess 1, meta info version:0
2022-12-16 20:18:47.624 1398-1398 MMKV com.atlantis.launcher I <MMKV_IO.cpp:130::loadFromFile> loaded [UserConfig] with 0 key-values
2022-12-16 20:18:55.256 1398-1398 MMKV com.atlantis.launcher I <MMKV_IO.cpp:451::writeActualSize> [UserConfig] increase sequence to 1, crc 1285129681, actualSize 4
2022-12-16 20:18:55.341 1398-1398 MMKV com.atlantis.launcher I <MMKV_IO.cpp:451::writeActualSize> [mmkv.default] increase sequence to 1, crc 1285129681, actualSize 4
---------------------------- PROCESS ENDED (1398) for package com.atlantis.launcher ----------------------------
---------------------------- PROCESS STARTED (2214) for package com.atlantis.launcher ----------------------------
2022-12-16 20:19:34.953 2214-2214 MMKV com.atlantis.launcher I Enable checkProcessMode()
2022-12-16 20:19:34.956 2214-2214 MMKV com.atlantis.launcher I native-bridge.cpp:104::JNI_OnLoad current API level = 28, libc++_shared=0
2022-12-16 20:19:34.957 2214-2214 MMKV com.atlantis.launcher I MMKV.cpp:165::initialize version v1.2.14, page size 4096, arch arm64-v8a
2022-12-16 20:19:34.957 2214-2214 MMKV com.atlantis.launcher I MMKV.cpp:176::initialize armv8 AES instructions is supported
2022-12-16 20:19:34.957 2214-2214 MMKV com.atlantis.launcher I MMKV.cpp:184::initialize armv8 CRC32 instructions is supported
2022-12-16 20:19:34.957 2214-2214 MMKV com.atlantis.launcher I MMKV.cpp:207::initializeMMKV root dir: /data/user/0/com.atlantis.launcher/files/mmkv
2022-12-16 20:19:35.139 2214-2214 MMKV com.atlantis.launcher I MemoryFile.cpp:97::open open fd[0x58], /data/user/0/com.atlantis.launcher/files/mmkv/mmkv.default
2022-12-16 20:19:35.139 2214-2214 MMKV com.atlantis.launcher I MemoryFile.cpp:97::open open fd[0x59], /data/user/0/com.atlantis.launcher/files/mmkv/mmkv.default.crc
2022-12-16 20:19:35.139 2214-2214 MMKV com.atlantis.launcher I <MMKV_IO.cpp:81::loadFromFile> loading [mmkv.default] with 108 actual size, file size 4096, InterProcess 0, meta info version:3
2022-12-16 20:19:35.139 2214-2214 MMKV com.atlantis.launcher I <MMKV_IO.cpp:86::loadFromFile> loading [mmkv.default] with crc 329900609 sequence 1 version 3
2022-12-16 20:19:35.139 2214-2214 MMKV com.atlantis.launcher I <MMKV_IO.cpp:130::loadFromFile> loaded [mmkv.default] with 5 key-values
2022-12-16 20:19:35.164 2214-2214 MMKV com.atlantis.launcher I MemoryFile.cpp:97::open open fd[0x5b], /data/user/0/com.atlantis.launcher/files/mmkv/UserConfig
2022-12-16 20:19:35.164 2214-2214 MMKV com.atlantis.launcher I MemoryFile.cpp:97::open open fd[0x5c], /data/user/0/com.atlantis.launcher/files/mmkv/UserConfig.crc
2022-12-16 20:19:35.164 2214-2214 MMKV com.atlantis.launcher I <MMKV_IO.cpp:81::loadFromFile> loading [UserConfig] with 305 actual size, file size 4096, InterProcess 1, meta info version:3
2022-12-16 20:19:35.164 2214-2214 MMKV com.atlantis.launcher I <MMKV_IO.cpp:86::loadFromFile> loading [UserConfig] with crc 3594725849 sequence 1 version 3
2022-12-16 20:19:35.164 2214-2214 MMKV com.atlantis.launcher I <MMKV_IO.cpp:130::loadFromFile> loaded [UserConfig] with 9 key-values

@AtlantisFaded
Copy link
Author

以上log是基于设置了MULTI_PROCESS_MODE的情况下
image

不知道我使用的对不对,另外应用是单进程app。

感谢回复,之后有时间会将关键代码提取出来,做一个单独的demo,再看看结果。目前通过其他的bool绕过了这个问题(其他bool是正确的)。

@lingol
Copy link
Collaborator

lingol commented Dec 16, 2022

You should never store mmkv as a static variable.

@AtlantisFaded
Copy link
Author

2022-12-16 20:18:47.624 1398-1398 MMKV com.atlantis.launcher I <MMKV_IO.cpp:81::loadFromFile> loading [UserConfig] with 0 actual size, file size 4096, InterProcess 1, meta info version:0

The file has been deleted. You should check who and when it's deleted.

收到,但是搜了下,没有地方删除该key,唯一的一处删除是其他的key
image

我会新起一个demo,再看看,大佬快下班吧哈哈

@lingol
Copy link
Collaborator

lingol commented Dec 16, 2022

2022-12-16 20:18:47.624 1398-1398 MMKV com.atlantis.launcher I <MMKV_IO.cpp:81::loadFromFile> loading [UserConfig] with 0 actual size, file size 4096, InterProcess 1, meta info version:0

The file has been deleted. You should check who and when it's deleted.

收到,但是搜了下,没有地方删除该key,唯一的一处删除是其他的key

image

我会新起一个demo,再看看,大佬快下班吧哈哈

Ignore it. Check my latest reply instead.

@AtlantisFaded
Copy link
Author

You should never store mmkv as a static variable.

单独针对隐私弹窗数值读取,改成了每次 MMKV.defaultMMKV(),设置为true后,依然每次启动还是false
image

@lingol
Copy link
Collaborator

lingol commented Dec 16, 2022

That's strange. I guess you have to make a demo to figure it out.

@lingol
Copy link
Collaborator

lingol commented Dec 21, 2022

Any updates yet?

@lingol
Copy link
Collaborator

lingol commented Jan 3, 2023

Closed due to inactive.

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