Search code examples
androidandroid-4.4-kitkatpicasso

Picasso never calling completion handler while trying to load an image on Android


I am trying to load an image:

   Picasso.with(SelectActivity.this).load(picture).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            bmp = bitmap;
            findViewById(R.id.facebookButton).setEnabled(true);
            continueToEditing();
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            findViewById(R.id.facebookButton).setEnabled(true);
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    });

picture is a valid string to a reachable, valid JPEG image. I've got everything inside a try/catch block and I've got breakpoints on onBitmapLoaded, onBitmapFailed, and try/catch's catch block.

However, none of this is called. There is also nothing in logcat related to this, too. What am I doing wrong?


Solution

  • Try keeping a strong reference to the Target object as a class variable and give it a try.

    E.g.

    Target target;// Class variable
    //Now define this on your onCreate method
    target = new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            bmp = bitmap;
            findViewById(R.id.facebookButton).setEnabled(true);
            continueToEditing();
        }
    
        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            findViewById(R.id.facebookButton).setEnabled(true);
        }
    
        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
    
        }
    });
    //Now set the target on the Piccaso load LOC
    Picasso.with(SelectActivity.this).load(picture).into(target);