When I use Picasso in different activities and monitor network requests, what I see is that the first activity creates a network request for image A. Before image A is loaded the user may tap somewhere and open a second activity which also loads image A. Now I see a second network request has been opened to fetch A again, which means downloading twice the same image.
Is there any way to tell Picasso to instead wait for the first request to complete and reuse its results to avoid consuming bandwidth?
UPDATE: After testing a bit more I found out that the problem doesn't have anything to do with separate activities. I created a test from scratch where two different activities loaded an image and a single request was done for both, which is wonderful. The behaviour in my production app however keeps happening, and is likely due to images being resized and cropped to different sizes. In one activity the user image is displayed as a cropped miniature circle, on another it is shown without resizing. Here is an example which reproduces the problem:
String IMAGE_URL = "http://ift.tt/1BHKAWf";
Picasso.with(this)
.load(IMAGE_URL)
.into(mImage1);
Picasso.with(MainActivity.this)
.load(IMAGE_URL)
.resize(233, 333).centerCrop()
.into(mImage2);
This code will open and download the image url twice despite being the same resource because of the .resize(233, 333).centerCrop() line. If this line is removed, Picasso will do a single request and share the result among images. Since the behaviour without resizing is good, is this maybe a bug? For the record this happens using 2.5.0.
Aucun commentaire:
Enregistrer un commentaire