Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to place an XML file containing data within an Android app

I am new to Android development. I have an XML file with data that the app will read. Where should I keep this XML file? Should it be stored within the "value" folder?

like image 497
artist Avatar asked May 18 '11 21:05

artist


2 Answers

I'd say that depends. What do you save in your XML-File? There also is a res/xml-folder, where XML-Files can be kept. But Android does nearly anything with XML-Files, so you might want to read my little Tutorial about where to put which recourses.

Also, there is a difference between the assets and the res-directory's:

res

  • No subdirectorys are allowed under the specific resource-folders.
  • The R-class indexes all resources and provides simple access.
  • There are some simple methods which help reading files stored in the res-directory

assets

  • Subdirectorys are allowed (as much as you like).
  • No indexing by the R-class
  • Reading resources stored in assets is done using the AssetManager.
like image 67
Lukas Knuth Avatar answered Sep 20 '22 15:09

Lukas Knuth


You can put it in the res/raw folder. Then you will access it using:

getResources().openRawResource(resourceName)
like image 35
Zack Marrapese Avatar answered Sep 23 '22 15:09

Zack Marrapese