0

In my Android app, I have saved xml files that I parse to create an object. I am using the same XML files all the time so I was wondering is there a way I can kind of store the object so I don't need to recreate it each time the app is used.

I don't want to store it to the hard disc or shared preferences, basically I just want to hard code the object into my app so that the XML never needs to be parsed again.

Is this possible?

Mel
  • 6,214
  • 10
  • 54
  • 71
  • It's unclear to me. If you wish to hardcode these objects you don't even need to read the XML once. You just have to define static values in a class. But did I get the question properly? – Shlublu May 21 '14 at 10:27
  • I have a few dozen xml files that don't ever change. I use each one to automatically create an object. (The xml file structure is tricky so parsing the xml is the easiest way to do it). It seems inefficient to parse the same xml files each time and think it would be better to just have hardcoded objects... But perhaps I am wrong in my thinking, maybe it is more efficient to have the data in xml and parse it every time. I don't know... – Mel May 21 '14 at 11:04
  • Put the values in a static class maybe? – A Nice Guy May 21 '14 at 11:16
  • @Mel, why not parsing them once in a standalone utility program that would generate classes containing `static` values, in that case? You would just include these classes into your application as a replacement of the current XML processing and output. – Shlublu May 21 '14 at 12:10
  • Yes, that sounds good. But the "standalone utility program" sounds difficult! – Mel May 21 '14 at 13:03
  • @Mel, not necessarily. Currently, you actually have to convert your XML data into a memory structure. That would be the same here. But we cannot discuss that further here as this question becomes a bit too broad or opinion-based. – Shlublu May 21 '14 at 13:17
  • I'll work on that idea. Thanks. – Mel May 21 '14 at 13:36

0 Answers0