I am working on demo application in which I am using Picasso library v2.5.2. It is working fine on all android operating system version, but not in lollipop.
Image whose size is 130KB which is not loading for me. Images whose size is less are loading correctly.
Here is my code for downloading bitmap and set on imageview.
target = new Target() {
@Override
public void onPrepareLoad(Drawable drawable) {}
@Override
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
if(bitmap != null) {
imageView.setImageBitmap(bitmap);
}
}
@Override
public void onBitmapFailed(Drawable drawable) {}
};
Picasso.with(this).load(URL).into(target);
I'm not sure what extra stuff I have to do with this so that I will work on lollipop also or this is bug in lib ?
The latest version is 2.71828. Show activity on this post. Version 2.8 is the latest as of today's post Oct 04 2020 which was released this on Aug 10 2020.
It's a known problem. The problem is that Picasso keeps a weak reference for the Target
. To get it working you need to make it strong, by storing a Target
as a tag of view, for example.
target = new Target() {
@Override
public void onPrepareLoad(Drawable drawable) {}
@Override
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
if(bitmap != null) {
imageView.setImageBitmap(bitmap);
}
}
@Override
public void onBitmapFailed(Drawable drawable) {}
};
imageView.setTag(target);
Picasso.with(this).load(URL).into((Target) imageView.getTag());
EDIT:
I suggest you to use Glide, it's very similar to Picasso, and also recommended by Google. And as you can see in the end of this thread, the original developer solves this BitmapFactory problem by using extra buffer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With