Problem description

Using MMKV instead of native sharedPreference, on some Huawei phones, the configuration file will be lost for no reason and the entire application will feel like a re-installation.

Problems found by

At first I thought the data was cleared when the user logged out, but the problem was not required, so it was not an obvious code bug. Fortunately, at this time, my colleague’s mobile phone had some problems, so I took his mobile phone to debug and wanted to find the content stored by MMKV, but found that all the data stored by MMKV was lost.

I immediately thought of the reason for the loss, because the folder stored by MMKV is under /data/data/ package name /files/ MMKV. The garbage cleared by huawei’s own mobile phone manager is actually files and other folders, so it is very likely to be removed by Huawei’s mobile phone as garbage files.

Problem of closed-loop

At present, it has been replaced with native SP, and the problem is solved.