Images not being cached locally (using Universal Image Loader) - slow image load times

后端 未结 4 636
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 12:26

Description of the problem: I\'m creating a scrollable list of articles with thumbnails that\'s populated by my SQLite database. In general, it\'s \"workin

4条回答
  •  青春惊慌失措
    2020-12-14 12:53

    I was experiencing similar issues with images in list view. Possibly this answer will correct your wrong image problem.

    I just downloaded the sample project with UniversalImageLoader and it exhibits the same behavior you are describing.

    A few notes so far from looking through the source code.

    public static final int DEFAULT_THREAD_POOL_SIZE = 3;
    public static final int DEFAULT_THREAD_PRIORITY = Thread.NORM_PRIORITY - 1;
    public static final int DEFAULT_MEMORY_CACHE_SIZE = 2 * 1024 * 1024; // bytes
    

    This says that at any time there will be three threads downloading and max of 2MB of images. How big are the images you are downloading? Also are you caching to disk? If so, that will be slow.

    To configure some of the basic options in the ImageLoader you will need to pass in to displayImage:

     DisplayImageOptions options = new DisplayImageOptions.Builder()
         .showStubImage(R.drawable.stub_image)
         .cacheInMemory()
         .cacheOnDisc()
         .build();
    

    I would also like you to try these options:

    ImageLoaderConfiguration imageLoaderConfiguration = new ImageLoaderConfiguration.Builder(this)
        .enableLogging()
        .memoryCacheSize(41943040)
        .discCacheSize(104857600)
        .threadPoolSize(10)
        .build();
    
    imageLoader = ImageLoader.getInstance();
    imageLoader.init(imageLoaderConfiguration);
    

    With my testing, the images are on disk, but loading is still slow.

    After extensive testing, I determined the primary issue is that UniversalImageLoader is just slow. Specifically, the ImageLoader and LoadAndDisplayImageTask are holding up the works. I (very quickly) rewrote the LoadAndDisplayImageTask as an AsyncTask and it immediately performed better. You can download the forked version of the code on GitHub.

    Universal Image Loader with AsyncTasks

提交回复
热议问题