Picasso: into(Target target) but sometime only onPrepareLoad come .

Created on 28 Dec 2015  Â·  2Comments  Â·  Source: square/picasso

public void into(Target target) {}

sometime only onPrepareLoad come, onBitmapLoaded not come & onBitmapFailed not come.

it may be the problem below

if (!data.hasImage()) {
picasso.cancelRequest(target);
target.onPrepareLoad(setPlaceholder ? getPlaceholderDrawable() : null);
return;

}

here is my source code

Picasso.with(context).load(avatarModel.getUrl())
.placeholder(R.drawable.user_img_default)
.error(R.drawable.user_img_default)
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Log.i(TAG, "onBitmapLoaded: ");
saveUserAvatar(avatarModel);
if (callBack != null) {
callBack.onBitmapLoaded(bitmap, from);
}
}

                @Override
                public void onBitmapFailed(Drawable errorDrawable) {
                    Log.i(TAG, "onBitmapFailed: ");
                    saveUserAvatar(null);
                    if (callBack != null) {
                        callBack.onBitmapFailed(errorDrawable);
                    }
                }

                @Override
                public void onPrepareLoad(Drawable placeHolderDrawable) {
                    Log.i(TAG, "onPrepareLoad: ");
                    if (callBack != null) {
                        callBack.onPrepareLoad(placeHolderDrawable);
                    }
                }
            });

@JakeWharton I have been put forward this problem before。

Most helpful comment

Do not call into by passing in new Target(). Store the Target instance somewhere that will not be garbage collected (implement on a view, in a view tag, on a view holder) and pass the reference to into.

All 2 comments

Do not call into by passing in new Target(). Store the Target instance somewhere that will not be garbage collected (implement on a view, in a view tag, on a view holder) and pass the reference to into.

@hackill what was your solution for this as

@Override public void onPrepareLoad(Drawable placeHolderDrawable) { //placeHolderDrawable is returning null }

Was this page helpful?
0 / 5 - 0 ratings