Store static data in Android - custom resource? Store static data in Android - custom resource? xml xml

Store static data in Android - custom resource?


I think this is the BEST solution and i am already using this one to store Static-data in my every project.

For that...You can do one thing, make one xml file namely "temp.xml" ..and store the data in temp.xml as follows:

  <?xml version="1.0" encoding="utf-8"?> <rootelement1>    <subelement> Blob 1       <subsubelement> 23 </subsubelement>     <subsubelement> 42 </subsubelement>     </subelement>    <subelement>Blob 2          <subsubelement> 34 </subsubelement>    <subsubelement> 21 </subsubelement>    </subelement>    </rootelement1>

and then use XML PullParser technique to parse data.You can have coding samples of PullParsing technique on Example , refer this example for better idea.

Enjoy!!


The best way is to use the Android Resource Heirarchy.

In the res/values/ directory, you can store any number of key-value pairs for several basic data types. In your app, you would refer to them using an autogenerated resource id (name based on your resource's key). See the link above for more documentation and details.

Android also supports raw datafiles. You could store your data in the file directory under res/raw/yourfile.dat

You you create your data in whatever text based format you want and then read it on activity startup using the resource access apis.


I have used Simple for xml parsing in the past. I think it has the least amount of code if you know what to expect in xml, which in your case you do.

http://simple.sourceforge.net/