I have an ArrayList
with custom objects. Each custom object contains a variety of strings and numbers. I need the array to stick around even if the user leaves
Also with Kotlin:
fun SharedPreferences.Editor.putIntegerArrayList(key: String, list: ArrayList?): SharedPreferences.Editor {
putString(key, list?.joinToString(",") ?: "")
return this
}
fun SharedPreferences.getIntegerArrayList(key: String, defValue: ArrayList?): ArrayList? {
val value = getString(key, null)
if (value.isNullOrBlank())
return defValue
return ArrayList (value.split(",").map { it.toInt() })
}