I have an ArrayList
of custom, simple Serializable
objects I would like to cache to disk and read on re-launch. My data is very small, about 25 objects and at most 5 lists so I think SQLite would be overkill. In the iPhone world I would use NSKeyedArchiver
and NSKeyedUnarchiver
which works great. On Android I've attempted to do this with with a FileOutputStream
and ObjectOutputStream
and while the result is the same, the performance is terrible. Is there a better (read faster) way to cache small objects to the file system in Android?
For what it worth I cache some of my String data to disk using BufferedWriter/BufferedReader and it's very fast. Matter of fact it is faster than storing the same data to SharedPreferences. The code goes something like this (note that things happen faster when you provide buffer size)
final BufferedWriter out = new BufferedWriter(new FileWriter(file), 1024);
out.write(stuff);
out.close();
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