For the More Curious: Why Assets, Not Resources

Technically, you could have used resources in this chapter instead of assets. Resources can store sounds. Stash a file like 79_long_scream.wav in res/raw, and you can get at it with the ID R.raw.79_long_scream. With sounds stored as resources, you can do all the usual resource things, like having different sounds for different orientations, languages, versions of Android, and so on.

So why did we choose assets? The biggest reason is that BeatBox has a lot of sounds: more than 20 different files. Dealing with them all one by one in the resources system would have been cumbersome. Resources do not let you ship out all your sounds in one folder, nor do they allow you to give your resources anything other than a totally flat structure.

This is exactly what the assets system is great for. Assets are like a little file system that ships with your packaged application. With assets, you can use whatever folder structure you want.

So with assets, if you want to add a new sound file, all you have to do is add it to your sample_sounds folder. Since they give you this kind of organizational ability, assets are commonly used for loading graphics and sound in applications that have a lot of those things, like games.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
34.207.180.141