I am using Picasso library to manage my image uploading and caching. When I am trying to execute this code:
Picasso.with(this)
.load(AppServer.getImageUrl() + "/" + eventInfo.getImageName())
.placeholder(R.drawable.calendar)
.error(R.drawable.calendar)
.into(new Target()
{
@Override
public void onPrepareLoad(Drawable drawable)
{
}
@Override
public void onBitmapLoaded(Bitmap photo, Picasso.LoadedFrom from)
{
cropImage(photo); //not getting here
}
@Override
public void onBitmapFailed(Drawable arg0)
{
}
});
I am not entering int the onBitmapLoaded
callback. Only if I close the activity (going back) and re opening it I see the image (entering into onBitmapLoaded
).
But if I will change my code by just adding some Toast
message into the onPrepareLoad
callback every thing works fine. here is the full code:
Picasso.with(this)
.load(AppServer.getImageUrl() + "/" + eventInfo.getImageName())
.placeholder(R.drawable.calendar)
.error(R.drawable.calendar)
.into(new Target()
{
@Override
public void onPrepareLoad(Drawable drawable)
{
Toast.makeText(thisActivity, "message", Toast.LENGTH_LONG).show();
}
@Override
public void onBitmapLoaded(Bitmap photo, Picasso.LoadedFrom from)
{
cropImage(photo);
}
@Override
public void onBitmapFailed(Drawable arg0)
{
}
});
Why the Toast makes it work? what is wrong with it?
I solved the issue by declaring a
Target
instance as class member. then initialised it. Like this: