I'm designing an app which involves parsing a large XML and keeping the serialised data accessible throughout the application. I intend to have a data object which will keep the data stored and each component (though not every one) can access the data.
I would like this data to be non-persistent, whereby the application parses the XML and keeps the data in memory. Note this data will be large (XML file is >2MB). Also, I would like the data to be there when a user switches to another app.
I have looked into possible solutions, such as:
- Static objects
- Singletons
- Extending Application
- Using a Service
- Using a SQLite database (I don't want to do this)
I do not want to get in to the endless argument of Singletons vs. extending Application, etc. but I would like to do unit tests as well and I've heard that Singletons and static objects are hard to test.
Can anyone shed some light on this? What would be the most elegant way to do it?
Edit: Should the data be persistent or not? Making it persistent would mean that there would, in theory, be one parse of the XML, serialises it, stores the data in a database and could use an object to access that data from the component. How does that sound?
Edit 2: I think the way I am going to keep the data accessible throughout the application is to use an SQLite database which will store the data.
Using the XML file, I will parse the data and put it in the database on first launch using a created subclass of SQLiteOpenHelper. When the data is needed I will make queries to the database using the subclass using read access. Each component (Activity/Service/etc.) would have its own instance of the SQLiteOpenHelper to make queries to the database and thus have access to the data. How does this sound?