0

I am currently programming in Android Studio, using Picasso library to load pictures as a background

Now is the problem, most of the times it does work. Picasso loads the picture and then set it as background. But sometimes it will show a blank background.

This is the code i use:

                Picasso.with(getContext()).load(picurl).into(new Target() {
                @Override
                public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                    Drawable d = new BitmapDrawable(getResources(), bitmap);
                    rl.setBackground(d);
                }

                @Override
                public void onBitmapFailed(Drawable errorDrawable) {

                }

                @Override
                public void onPrepareLoad(Drawable placeHolderDrawable) {

                }
            });     

How can i take care of my code to make it show background 100% of the times instead of 50%?

I placed the Picasso method in the onCreate() method of my fragment.

I also used the Picasso logging and this is what i got:

D/Picasso: Main        canceled     [R1]+81ms target got garbage collected
D/Picasso: Hunter      decoded      [R1]+123ms 
D/Picasso: Dispatcher  batched      [R1]+123ms for completion
D/Picasso: Dispatcher  delivered    [R1]+325ms 
D/Picasso: Main        completed    [R1]+325ms from DISK

It is telling me that it loaded and completed the picture. but it is still not being shown as my background.

Alex Hakman
  • 62
  • 1
  • 8
  • 1
    Have you tried loading it into an imageview just to see if it appears there? – MichaelStoddart Nov 23 '16 at 14:51
  • With an imageview i have the same problem, like 50% of the time it loads. Same as background – Alex Hakman Nov 23 '16 at 14:56
  • Do you still use new Target when using just an imageview? – MichaelStoddart Nov 23 '16 at 15:05
  • try put a breakpoint at setBackground() of your target, see if anything overwrote your image after your image delivered. – yongsunCN Nov 23 '16 at 15:29
  • @TheAndroidDev I used it without the Target, and now it worked, while background was still white. So now its time to figure out a way to .load().into(backgroundoffragment) – Alex Hakman Nov 23 '16 at 15:35
  • 1
    there is a known issue with using Target and android only holding a weak reference to it see this SO post http://stackoverflow.com/questions/24180805/onbitmaploaded-of-target-object-not-called-on-first-load – MichaelStoddart Nov 23 '16 at 15:37

0 Answers0