Cache of android images-saving memory and improving Program Efficiency,
Currently, android applications account for a larger percentage of memory, and the quality of android applications needs to be improved.
Here is a brief introduction to the cache of network images. Here is a simple introduction of ideas.
1: network images are undoubtedly required to be downloaded. We do not need to download images every time.
Maintain a table with the stored file name corresponding to the url
The implementation method is to get the url to be downloaded and match it with the database. If this image exists, you do not need to download it again. You can directly obtain the image location through the database, then load the image from the local machine and it will be OK. If you do not have this image, download it and save it to the database.
Benefits: the benefits of this operation are obvious. You do not need to download the downloaded images again, which saves local space. It is not a good thing to download multiple identical images and put them locally.
2: Memory Processing of image resources. An image needs to be displayed in multiple places. For example, you need to display your profile picture in many places. You do not need to load this image everywhere, this will waste a lot of resources.
Implementation Method: maintain a Bitmap MAP in the memory, put the key in the url, and put the value in the Bitmap. We get a url and check whether the image exists in the memory.
Benefit: bitmap occupies a lot of memory. reusing it can save a lot of memory. Second, loading images locally also consumes resources. If you load each image once, will it be much better.
To achieve these two points, we can see a lot more efficiency in the image. I won't talk about OOM. I hope you will be helpful in program optimization, as for this tool class, I can write it again when I have time. There are also a lot of online tools. I want to write this blog to see if I can get a few C coins. I am very busy recently and have no time to write a blog, it may be helpful for everyone to write a mix of C coins.