Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple ImageLoader instances #92

Closed
artem-zinnatullin opened this issue Oct 29, 2012 · 7 comments
Closed

Multiple ImageLoader instances #92

artem-zinnatullin opened this issue Oct 29, 2012 · 7 comments
Labels

Comments

@artem-zinnatullin
Copy link

In my app I have got 3 types of images to load, all of types needed different ImageLoaderConfiguration.

Images types example:
  • Users avatars (cache on disc, memory cache size ~ 5mb, thread pool size ~ 3, thread priority min + 3, medium compression)
  • News feed pictures (cache on disc, memory cache size ~ 1mb, thread pool size ~ 5, etc..)
  • Temporary images, like friends photos, etc.. (no cache, thread pool size ~ 2,..)

Sometimes it needed to use different ImageDownloader or FileNameGenerator or something else, but it is not possible at the moment because ImageLoader is singleton class.

So, what about many ImageLoader objects?

May be it will be good to use ImageLoaderFactory and class-containter for created ImageLoader objects to use them, or something else.

What do you think about it?

@nostra13
Copy link
Owner

First of all cache on disc/no cache is configured not in configuration but in display options for every displayImage(...) call.

Ok, I understand your use case.
I''l make ImageLoader's constructor protected so you can make new ImageLoader instance like this:

public class AnotherImageLoader extends ImageLoader {

    private volatile static AnotherImageLoader instance;

    /** Returns singletone class instance */
    public static AnotherImageLoader getInstance() {
        if (instance == null) {
            synchronized (ImageLoader.class) {
                if (instance == null) {
                    instance = new AnotherImageLoader();
                }
            }
        }
        return instance;
    }
}

But be careful about sizes of memory caches (don't make summary caches size too big) and folders for disc caches (if you use limited disc caches then consider using different folders for caches).

Changes will be available in new lib version.

@artem-zinnatullin
Copy link
Author

Thanks, at the moment I have got exactly the same solution, ImageLoader constructor is protected

@lordzden
Copy link

@nostra13 : the resolution helped me alot on this issue! Thank you for your answer. I had multitple use of UIL in my application from fragments to child fragments.

@nostra13
Copy link
Owner

You're welcome :)

@lordzden
Copy link

By the way I'd like to know why if the UIL not working if I am using 2 Activities with respective fragments with child fragments on the background. I declared it just the simple way for each of them.

@accandme
Copy link

accandme commented Nov 3, 2014

Thanks for this.

One comment: shouldn't the synchronized block be on AnotherImageLoader.class ?

@nostra13
Copy link
Owner

nostra13 commented Nov 3, 2014

It seems so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants