Why should I keep audio and video files inside the raw folder?

2

On Android, you have within the res directory several subdirectories, apparently separated for better organization. Sometimes when you want to put a new audio, for example to touch, different from the standards of the device, it is advisable to put it in a folder called raw .

Why should I keep audio and video files inside the raw folder? Is there any special treatment so we have to keep them within this directory? Is there any consequence or loss of performance when putting an audio file inside the drawable directory?

    
asked by anonymous 25.03.2017 / 21:16

1 answer

3

Android SDK tools compile resources ( resources ) along with the application (1) binary. During this process, symbols (class R) are generated for each one, so that they can be accessed in the code.

The class R contains code for all resources in the res / folder. For each resource type, there is a subclass R ( R.drawable , R.layout , etc.) and, for each resource of that type, an integer (id) that identifies it. id is used in the code to reference it when you want to use the feature.

To allow this mechanism, Android has a predefined folder structure and forces each resource type to be placed in the respective folder of that structure.

So, it's not a question of " devo " or " performance " but rather the way Android treats application features that require every resource type is placed in the respective folder.

(1)
- Files placed in the res / raw folder are not compiled, only entries in the R class are generated.
- The files placed in the java / assets folder are not compiled and no entry will be generated in the R class.

References:

26.03.2017 / 00:01