Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Accessing images from assets/drawable folders

The app I am currently working on has hundreds of images. At the moment I store them in the 'Drawable' folder. I was thinking about moving all of them to Assets folder.

My question is: Is there any difference in performance when using both approaches?

like image 587
Marqs Avatar asked Dec 06 '11 12:12

Marqs


People also ask

How do I get a list of images in a specific folder on Android?

You can use below code to get all images from specific folder. 1) First you need to define File object to get the storage and appened the name of the folder you want to read. File folder = new File(Environment. getExternalStorageDirectory().

How do I get to the drawable folder on Android?

You can however, add all image files under /drawable and then access them programmatically via: int drawableID = context. getResources(). getIdentifier("drawableName", "drawable", getPackageName()); iv.


2 Answers

I don't think so there is bit difference in performance of using these two folders, I think using drawable folder you can get easily images (All will be indexed in the R file, which makes it much faster (and much easier!) to load them.), and If you want to use it from asset then you have to use AssetManager then using AssetFileDescriptor you have to get those images.

  • Assets can also be organized into a folder hierarchy, which is not supported by resources. It's a different way of managing data. Although resources cover most of the cases, assets have their occasional use.

  • In the res/drawable directory each file is given a pre-compiled ID which can be accessed easily through R.id.[res id]. This is useful to quickly and easily access images, sounds, icons...

like image 118
user370305 Avatar answered Oct 08 '22 10:10

user370305


As far as I know, there shouldn't be big difference but I would rather go with Drawable.

Drawable gives you, beside indexing, option to fight with screen density fragmentation and Assets shouldn't depend on density. Having big pictures on smaller screens and/or lower specification phones (RAM, CPU) can cause real trouble and influence usability and app responsivity.

like image 34
vbokan Avatar answered Oct 08 '22 09:10

vbokan