Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Android
How to remove item in Array in shared preference
Maha Sakka
Ranch Hand
Posts: 179
1
posted 4 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I want to remove an item with id = "productId" from an Array with key stored in sharedPreferences.
I write this function but the item still exist in the Array stored, how could i change my code to reach my goal
fun removeArrayDataByKeyValue(key: String, productId: String) { val prod = getArrayDataByKey(key) sharedPreferences.edit().remove(productId).apply() if (prod != null) { setArrayDataByKeyValue(key,prod) } }
fun setArrayDataByKeyValue(key: String, DataArrayList: Array<ProductData>) { val arrayString = Gson().toJson(DataArrayList) sharedPreferences.edit().putString(key, arrayString).apply() }
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Kotlin: How to remove element from ArrayList in SharedPreferences
How to stored a data with sharedPreferences in Kotlin
How to remove SharedPreference after on itemclick in recycler view with kotlin
java.lang.IllegalStateException: Gson().fromJson(json,type) must not be null
instantiating an interface
More...