Before answering the difference, a brief explanation about the Resources:
Some items must be externalized (images, strings) to keep them independent and to support specific settings (device language, screen size, orientation, etc.). The briefcase res
, uses several subfolders that join the Resources by type and configuration.
Mark Vasconcelos, in his article on Android - Application structure and organization, made a "summary" on the structuring of the application:
Folders created automatically in the project that will be used by
application are:
src
: That’s where our application’s source code is.
res
: Folder of Resources application, here will be layout files, images, XML configuration, XML with strings
internationalizable, raw files, sounds, etc..
The folders created by default for Resources sane:
res/drawable-<screen cfg>
: The images should be placed, the division between hdpi (High dpi), mdpi (Medium dpi), ldpi (Low dpi) is
to save the images in different resolutions.
res/layout
: There are Xmls files that represent the layout of our Activities
.
res/values
: Xmls that store strings that can be used in the application.
For default, an archive strings.xml
is created in that folder, the
values are saved through tags with the following structure
<string name="nomeString">Valor String</string>
In the folder res
it is possible to add more subfolders to
represent more Resources for application or alternatives to
Resources, such as a folder xml
to save settings information.
gen
: source folder generated
This folder also stores source code, but it only keeps a single source
automatically generated class of the eclipse plugin named "R" in
same package we reported in "package name" when we created our
project. This class R
contains ids for all items we have on
briefcase res
, and it is through these ids that we can use all the
Resources easily in our application.
assets
: raw files - The difference of putting files raw
here than in something like res/raw
is that Resources sane
accessible by id through class R
, files in that folder can
be opened by stream within the application as a byte array.
You can still add more folders to the project to create
native applications is created a folder named jni who guards the
native codes and AndroidMakeFiles
than Android NDK (Native
Development Kit) uses to create Shared lib for application, such as
Android is a Unix distro, Shared lib is a file with extension
.only, the files generated by NDK still goes to another folder called libs, this folder contains the Shared libs that can be used in
application in Runtime
, which can be loaded with a
System.loadLibrary(“nomeLib”)
.
That’s worth reading about reply stackoverflow.
What is the real difference between raw
, the assets
and the res
on Android, and how I could use each of them?
res
: You should always use the files and folders of Resource to store your application’s values in addition to the images, of course. This way you can maintain and update your code much more easily, and you can define alternatives for each of them, according to specific situations, such as different languages, sizes and screen orientations. The briefcase res/
is the folder of your project that stores all the Resources of its application
raw
: Save active files instead of saving to assets/directory
. The difference is in the way you will access them. These files are processed by aapt and must be referenced from the application that uses a resource identifier in the class R
. For example, this is a good place for media like MP3 or Ogg.
assets
: It is more like a file system and offers more freedom to put any file. Then you can access each of the files on that system. This directory is good for things like game details, dictionaries, ... etc.
Reference: