MMKV Android: High-Performance Storage Guide
MMKV is a high-performance Key-Value storage library designed to replace SharedPreferences on Android. By using MMKV on Android, you can boost data storage performance and efficiency. Check out the following example of how to use MMKV in Android.
- Add dependency:
Add the dependency for MMKV in the build.gradle file of the project.
implementation 'com.tencent:mmkv:1.2.10'
- Initialize MMKV:
Initialize MMKV in the onCreate() method of the Application.
MMKV.initialize(this);
- Storage of data:
Data can be stored using MMKV, using methods such as putXXX().
MMKV mmkv = MMKV.defaultMMKV();
mmkv.putString("key", "value");
- To retrieve data:
You can retrieve data using the getXXX() method, for example:
MMKV mmkv = MMKV.defaultMMKV();
String value = mmkv.getString("key", "");
- Delete data:
You can remove specified data using the remove() method, for example:
MMKV mmkv = MMKV.defaultMMKV();
mmkv.remove("key");
- Other functions:
MMKV also offers additional features such as setting encryption, setting the root directory, which can be configured and used according to actual needs.
In general, using MMKV can provide more efficient data storage and retrieval operations, and in scenarios where performance is crucial, it is worth considering using MMKV instead of SharedPreferences.