Cache of android images-saving memory and improving Program Efficiency,

Source: Internet
Author: User

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.





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.