I'm trying to load an image into my view. Sometimes it works, sometimes it does not. I'm testing on an API level 19 emulator. The failure block inside of the new Target is never called. I see prepareLoad
and then either:
onBitmapLoaded
is called, the image will show- The image will not show
Why would this be happening?
This is occurring on the emulator. On a physical device, Q&A has reported 100% failure rate. On other devices I see intermittent failure rate. What's going on here?
public void setBackground() {
final LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout);
final Context context = this;
final String imagePath = getStore().backgroundImageURI;
if (getStore().backgroundImageNumber > 0) {
mainLayout.setBackground(context.getResources().getDrawable(getStore().backgroundImageNumber));
return;
}
if (imagePath == null) {
mainLayout.setBackground(context.getResources().getDrawable(R.drawable.sk_collection_bg_default));
return;
}
Picasso.with(this).load(imagePath).into(new Target(){
@Override
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
Log.v("Biscuit-width", String.valueOf(bitmap.getWidth()));
Log.v("Biscuit-height", String.valueOf(bitmap.getHeight()));
mainLayout.setBackground(new BitmapDrawable(context.getResources(), bitmap));
}
@Override
public void onBitmapFailed(final Drawable errorDrawable)
{
Log.d("BISCUIT", "FAILED" + errorDrawable.toString());
}
@Override
public void onPrepareLoad(final Drawable placeHolderDrawable) {
Log.d("TAG", "Prepare Load");
}
});
}