Cache of Android Images-save memory and improve program efficiency

Source: Internet
Author: User

Android apps now account for a larger memory than one, and the quality of Android programs needs to be improved.

Here is a brief description of the network image cache, my side of the simple talk about ideas


1: Network pictures, undoubtedly need to download pictures, we do not need to download each time.

Maintain a table, the table contains the URL corresponding to the stored file name

The implementation method is to get the URL to download, take this URL to the database match, if there is this picture, it does not need to re-download, directly through the database, to get the location of the picture, and then from the local loading the picture is OK. When you don't have this picture, download it and save the database.

Benefits: The benefits of doing so obviously, downloaded pictures do not need to re-download, but also save the local space, download many of the same picture local is not good.


2: Image resources memory processing, a picture needs to be displayed in many places, such as their avatar, need to show in many places, do not need every place to load this picture, this will waste a lot of resources.

Implementation method, in memory to maintain a bitmap map,key put Url,value put this bitmap we get a URL, first see if there is this image in memory, there is directly from the use.

Benefits: Bitmap is very memory, reuse it can save a lot of memory, and then load the picture from the local also need to consume resources, each picture as long as the load once, this is not much better.


To achieve these two points, the image of the efficiency of this piece can be seen a lot more, oom god horse I will not say, write this hope everyone to the program optimization will have some help, as for this tool class have time to write it, online also have a lot of, write this blog also want to see can get a few C coins, recently very busy, Also have no time to write a blog, roughly write a gangster C-money, for everyone should also be a bit of help


Cache of Android Images-save memory and improve program efficiency

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.