1

in this tutorial for "learning to parse XML data in your Android App" the author puts his XML file into the assets folder. But in other tutorials they recommend to use res/xml. None of them explains why they took the folder they use.

What is the difference between those two folders? What is best practice? Is there a difference in performance?

Fraggles
  • 463
  • 4
  • 20

2 Answers2

4

The res folder is used to put authorized resources files type, like layout(xml), drawable (png, jpg, xml), raw (mp3, ogg), etc... In the assets folder, you can put all files types you want (txt, avi, png, docx, xyz, ext, asm, ....).

Check this : Android Projects Structure

1) assets/

This is empty. You can use it to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the AssetManager. For example, this is a good location for textures and game data.

2) res/

Contains application resources, such as drawable files, layout files, and string values. See Application Resources for more information.

  • anim/

For XML files that are compiled into animation objects. See the Animation resource type.

  • color/

For XML files that describe colors. See the Color Values resource type.

  • drawable/

For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or focused). See the Drawable resource type.

  • layout/

XML files that are compiled into screen layouts (or part of a screen). See the Layout resource type.

  • menu/

For XML files that define application menus. See the Menus resource type.

  • raw/

For arbitrary raw asset files. Saving asset files here instead of in the assets/ directory only differs in the way that you access them. These files are processed by aapt and must be referenced from the application using a resource identifier in the R class. For example, this is a good place for media, such as MP3 or Ogg files.

  • values/

For XML files that are compiled into many kinds of resource. Unlike other resources in the res/ directory, resources written to XML files in this folder are not referenced by the file name. Instead, the XML element type controls how the resources is defined within them are placed into the R class.

  • xml/

For miscellaneous XML files that configure application components. For example, an XML file that defines a PreferenceScreen, AppWidgetProviderInfo, or Searchability Metadata. See Application Resources for more information about configuring these application components.

GhoRiser
  • 686
  • 4
  • 3
1

The difference between "resources" and "assets" isn't much on the surface, but in general, you'll use resources to store your external content much more often than you'll use assets. The real difference is that anything placed in the resources directory will be easily accessible from your application from the R class, which is compiled by Android. Whereas, anything placed in the assets directory will maintain its raw file format and, in order to read it, you must use the AssetManager to read the file as a stream of bytes. So keeping files and data in resources (res/) makes them easily accessible.

For details you can see following links : Link1, Link2

Shahinoor Shahin
  • 685
  • 3
  • 14