1、引入依赖
implementation 'com.tencent:mmkv-static:1.2.9'
2、初始化
在自定义的Application的onCreate()中
MMKV.initialize(this);
3、实现
public class SpUtils {
private static final String PREFERENCE_NAME = "config";
private static SpUtils INSTANCE;
private final MMKV mmkv;
private SpUtils() {
mmkv = MMKV.defaultMMKV();
//迁移
SharedPreferences sharedPreferences = XTApplication.getAppContext().getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
if (!sharedPreferences.getAll().isEmpty()) {
mmkv.importFromSharedPreferences(sharedPreferences);
sharedPreferences.edit().clear().apply();
}
}
public static SpUtils get() {
if (INSTANCE == null) {
synchronized (PREFERENCE_NAME) {
if