Jetpack DataStore 基础使用简单封装
在Application下初始化
DataStoreUtil.instance.init(this)
写入数据
suspend inline fun <reified T : Any> dataStoreSave(key: String,value: T) = when(T::class){
String::class -> DataStoreUtil.instance.mDataStorePre.edit { it[preferencesKey<T>(key)] = value }
Int::class -> DataStoreUtil.instance.mDataStorePre.edit { it[preferencesKey<T>(key)] = value }
Boolean::class -> DataStoreUtil.instance.mDataStorePre.edit { it[preferencesKey<T>(key)] = value }
else -> throw IllegalArgumentException("Type not supported: ${T::class.java}")
}
获取数据
suspend inline fun <reified T : Any> dataStoreRead(key : String) = when(T::class){
Strin