Assuming a method of mine was passed a Bundle already filled with data to be saved, is there a way to save it to SharedPreferences without taking it apart to ints, floats, Strings, etc.?
I prefer the convenience of writing/committing it all in "one fell swoop", so if this isn't possible using SharedPreferences, what other persistent storage approach would you recommend?
You can save String and custom array list using Gson library. =>First you need to create function to save array list to SharedPreferences. public void saveListInLocal(ArrayList<String> list, String key) { SharedPreferences prefs = getSharedPreferences("AppName", Context. MODE_PRIVATE); SharedPreferences.
there is no limit in Shared Preference. Save this answer.
DataStore is a new and improved data storage solution aimed at replacing SharedPreferences. Built on Kotlin coroutines and Flow, DataStore provides two different implementations: Proto DataStore, that stores typed objects (backed by protocol buffers) and Preferences DataStore, that stores key-value pairs.
SharedPreferences are serialized to XML, which is why you can only use simple types. You'll either have to do your own conversion of the bundle to individual SharePreferences properties or serialize the bundle some other way to disk.
Here's a good reference document discussing the various possibilities of storing data in Android: http://developer.android.com/guide/topics/data/data-storage.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With