0

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.

Freelancer
  • 836
  • 1
  • 14
  • 47
HarveyDX
  • 27
  • 5
  • Yes, use a database and then do it asynchronously. Modifying an xml file means re-writing the whole file each time, which is obviously terribly slow when it gets as large as a few Megabytes. – zapl Dec 16 '14 at 18:24
  • Thx for your reply. I just wrote 1.000.000 items to xml and try to read them, and it crashed horribly. A user won't insert that much data in the real app, but still. I will look into database and asynch then. Thanks. Should I close the topic? (And how do I do that?) – HarveyDX Dec 16 '14 at 18:29

1 Answers1

0

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.

diaz994
  • 354
  • 3
  • 13