Hallow Per
Hallow Per

Reputation: 31

Most efficient way to load a lot of images from URL Android

I'm making this netflix style app in which images are loaded into different categories. Let's say Dog videos (has 15 images), Cat videos (15 images), etc... All the images are loaded from a URL, it kind of takes a while for all to load. I was wondering if there was anything I could do to speed up the process? Or maybe show an empty container then fill it as the images load (that would be cool).

This is what I have done:

I have multiple async calls in one Activity, (1 async call per category)

JSONTask1 dogTask = new JSONTask1();
JSONTask2 catTask = new JSONTask2();
JSONTask3 pigTask = new JSONTask3();
JSONTask4 horseTask = new JSONTask4();

dogTask.execute("");
catTask.execute("");
pigTask.execute("");
horseTask.execute("");

I have all of those in a row in my actual code. Thanks.

Upvotes: 3

Views: 998

Answers (3)

Yasin Kaçmaz
Yasin Kaçmaz

Reputation: 6663

You can see Picasso answers , in picasso i suggest you this way :

Picasso.with(getApplicationContext()).load("your url").placeholder(R.drawable.your_place_holder).error(R.drawable.showing_when_error_occured)
            .into(imageView, new Callback() {
        @Override
        public void onSuccess() {

        }


        @Override
        public void onError() {

        }
    });

Also another suggestion from me : convert your thumb images to base64 format in backend, then firstly retrieve your thumbs and show them. Then start an async task and change images when successfull. Like whatsapp. In whatsapp you have thumb images they have so low resolution and super fast. When you click image if you have internet connection they load actual thumb images, and click again they load larger image.

Picasso website :http://square.github.io/picasso/

Upvotes: 1

MasterJohn
MasterJohn

Reputation: 439

I would use the "proxy pattern". Basically, you need to create a class that contains the minimal informations required for the display. In which, you have a preview image. When ever you load everything you start by showing the preview content, ie : a loading gif for everypicture with the title of the movie or whatever. and basically the proxy would have a "loadImage" method that would make an ajax call or async call and the photos would load one by one. Plus, to make the loading easier, make sure the photos are not oversized.

Upvotes: 2

user6304752
user6304752

Reputation: 11

Load them asynchronously with Picasso, you can even show a placeholder image until the real one is loaded

Upvotes: -1

Related Questions