Are Android cache downloadable resources loaded into xml layout files?

I have a ViewPager that loads a lot of fragments (+20). Each of these fragments is just an instance of one single fragment, and the only thing that changes is the content of each of them. The user interface for this fragment has, among other widgets, 4 different ImageViews that load the same resource, but, of course, are located in different parts of the user interface.

Now, considering that I can have, for example, 20 fragments with this scheme, we are talking about 80 (20 * 4) ImageViews that will load the same.

So this made me wonder if the Android cache really somehow loads resources from xml layouts? If not, is there a better option by simply loading this code into the code, caching it and linking it to the corresponding ImageView programmatically each time a new instance of this fragment is created?

Thanks.

+6
source share
3 answers

Android has some sort of recycling control with the Drawable component. I noticed this very clearly when using the same resources for Drawables and using ColorFilter with them, and I ended up seeing the wrong color with the previously created drawable, which was not yet visible in the user interface.

I would say your approach is fine.

In this post, Romain explains that Drawables conveys some information, like Bitmap they draw: http://www.curious-creature.org/category/android/page/2/

+6
source

Just a summary of the blog post provided in the accepted answer, so people don’t need to read the entire blog. In an example in a blog post, the author talks about creating different buttons that will ultimately have the same features:

Thus, all buttons in all applications have the same bitmap, which saves a lot of memory.

So yes, obviously, Android does optimize the downloaded resources.

+3
source

Here's how you modify the image viewer image:

  Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.your_drawable); your_imageView.setImageBitmap(bitmap); 

hope this help you can find here more tutoriel click here

-4
source

All Articles