I was planning (and implemented -_- my bad because didn't read anything on this article) to use Java Serialization for creating data files from my objects, but as i noticed right now, it's fairly SLOW on android even with powerful devices.
Simply, i have an application that stores dozens of Stroke objects, i need to save and load those objects for later use. My current workflow looks like that ;
public class StrokePoint extends PointF implements Serializable { ... }
public class CardinalStroke extends Stroke implements Serializable {
...
protected ArrayList<StrokePoint> mPoints = new ArrayList<StrokePoint>();
...
}
Finally, i have a class which is containing stroke objects, and the other things, it looks like ;
public class NoteElement implements Serializable {
...
private ArrayList<IStroke> mStrokes = new ArrayList<IStroke>();
...
}
I'm using for serialization that code and saving serialized data into SQLITE DB (should i keep using SQLITE for this use or is it better to save those data into FILE for future using.);
private void saveElement(NoteElement element) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(element);
mProvider.insertOrUpdateElement(mCurrentModel.getBookId(), element.getUuid(), baos.toByteArray());
element.setIsModified(false);
} catch (IOException e) {
}
}
When i run saveElement serialization keeps about 500+ms at least with non-complex elements, i could have very complex NoteElements, they will keep probably 2000ms+ which is not acceptable for serializing that data, also saving into SQLITE keeps like Serialization/4 ms.
Well regarding my question is, How can I improve serialization speed, or should i use completely different technique for that kind of data storage. I read about Percelable but that couldn't be used for data storage maybe there is some alternative built-in or should i implement my own data serializer classes which could be pain in some point ? I'm open for any kind of suggestions, Thanks for your time!
This Question is not about SQLITE Slow insertation, it's about slow Serialization. I wonder who is marked that question is marked as duplicate to Slow SQLITE inseration weird.