When my activity starts I check for an existing data file and if there isn’t one I call a web service that provides a blank one to begin with. The file is read into an ArrayList collection and the user makes changes as needed. Now I am in need of advice for the best approach.
Should I try to match the updated contents in the ArrayList to the element in the XML file (there is an ID field that could be used for matching) or should I just write out the ArrayList overwriting the old xml file? No worries about maintaining a hx.
If I write out the file (what I’m thinking is the way to go) do I have to decorate everything in the DataObject class (ie all the properties) as serializable or just at the class level. Do I also somehow need to mark the ArrayList collection serializable as well?
There is no need to mark your
ArrayListorDataObjectas serializable if you just want to write it out as XML, check for e.g XStream for Basic Object to XML conversion.Also since you are containing the whole content in your
ArrayListwhich means at any given point in time yourArrayListcontains the updated data, if you just override the XML file it will be much easier for coding point of view as you need not do any dirty check.