Android Imageloader picture loading simple logic

Source: Internet
Author: User

1. Create a Imageloader object in singleton mode

2. Initialize LruCache(least recently using the algorithm's Cache tool class, http://www.cnblogs.com/tianzhijiexian/p/4248677.html), taking part of available memory to store pictures

3. Initialize disklrucache(HDD Cache)

4. Call the show Picture method

    • If you use a resource ID, set the picture directly for ImageView
    • Set tag as URL for ImageView
    • LRUCache Memory cache Take picture, if there is picture, set picture, return
    • Add the picture load request to the picture loading stack stack (LIFO), if the stack has the same request, delete it, and add the request to the top of the stack.
    • To start sending a picture load request:

If the picture load thread is empty, initialize the picture load thread (using handlerthread and handler)

  Loop : Take picture loading request from picture loading stack, load picture in picture loading handler

If it is a local picture, it is read directly, not read from Disklrucache, otherwise read from Disklrucache, if bitmap is not empty, add to LRUCache;

If it is a network picture, then load from the network, the process of loading, direct image compression , if the bitmap is not empty, added to the LRUCache and Disklrucache;

Notifies the UI thread to set bitmap for ImageView, determine whether the same imageview based on URL and tag, and then set the picture (to prevent image misalignment )

Continue Looping

Android Imageloader picture loading simple logic

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.