I have two questions. I'm working on an Android application that will store a list of items in xml
file. This list could potentially grow large, but it depends on the user. I'm using a DOM
parser for storing and SAX
parser for reading. Right now I'm just executing the read and write methods.
First question: Should I wrap the methods in a Thread
or AsynchTask
? I honestly have no idea how fast they parse for big amounts of data.
Second question: Should I be using a different kind of data container for storing data? Database or something.
Thanks in advance.
Answer to your first question: If you try to write to the file with multiple threads there needs to be some coordination among your threads, you really want to avoid doing them at the exact same time. Either you need to synchronize file access and only write whole record/lines, or you need to have a strategy for allocating regions of the file to different threads e.g. re-building a file with known offsets and sizes.
Answer to your second question: You should most definitely try using a database for storage and then access it asynchronously.
So, migrate your application to write and read from a database, it will make your end user experience better and your application faster.