I was planing on using the writeObject to write my array lists to the internal storage. However, I don’t know how to save/restore more than one of them. Like with SharedPreferences it makes key/value pairs, but with three ArrayLists, how can I save them and then restore them back when needed?
I was planing on using the writeObject to write my array lists to the
Share
ObjectOutputStreamuses ajava.io.OutputStreamas argument in its constructor. SinceFileOutputStreamis a derived class of it, you can use it directly. Something like:Alternatively, if you want to use
SharedPreferencesinstead, you just need a way to serialize the whole ArrayList (perhaps using aObjectOutputStreamto aByteArrayOutputStream).A very easy way to do serialize the array (depending on the complexity of the objects stored) is to create a
JSONArrayto hold the ArrayList values, and use its built-intoString()method.