fun removeArrayDataByKeyValue(key: String, productId: String) {
val prod = getDataInArrayList(key)
val removeProduct = ProductData(
id = productId)
prod.remove(removeProduct)
if (prod != null) {
setDataInArrayList(prod, key)
}
}
fun setDataInArrayList(DataArrayList: ArrayList<ProductData>, key: String) {
val jsonString = Gson().toJson(DataArrayList)
sharedPreferences.edit().putString(key, jsonString).apply()
}
fun getDataInArrayList(key: String): ArrayList<ProductData> {
val emptyList = Gson().toJson(ArrayList<ProductData>())
return Gson().fromJson(
sharedPreferences.getString(key, emptyList),
object : TypeToken<ArrayList<ProductData>>() {
}.type
)
}
} }
THIS是类提供程序的代码,我不知道如何在splashScreen中应用函数getAllTodo将数据存储在列表中