question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Target sometimes work,sometime doesn't

See original GitHub issue

This is my scenario

// on FragmentActivity Class
    Picasso picasso = Picasso.with(this);
    String[] imageUrls = {
            "http://digital-photography-school.com/wp-content/uploads/2013/03/Acorn256.png",
            "http://stereo-ssc.nascom.nasa.gov/beacon/latest_256/behind_euvi_195_latest.jpg",
            "http://littleblackapp.blob.core.windows.net/product3071/img10020_0.png" };

    private void initLoadImages() {
        for (int i = 0; i < imageUrls.length; i++) {
            String imageUrl = imageUrls[i];
            picasso.getSnapshot().dump();
            CustomTarget target = new CustomTarget(imageView, progressBar,
                    index);
            picasso.load(imageUrl).into(target);

        }

    }

    // this class is within the Activity class
    public class CustomTarget implements Target {
        public ImageView imageView;
        public ProgressBar progressBar;

        public CustomTarget(ImageView imageView, ProgressBar progressBar,
                int position) {
            this.imageView = imageView;
            this.progressBar = progressBar;
        }

        @Override
        public void onBitmapLoaded(final Bitmap bitmap, LoadedFrom from) {
            Log.i("bitmap loaded", "bitmap loaded");
            imageView.setImageBitmap(bitmap);

        }

        @Override
        public void onBitmapFailed() {

        }

    }

The custom target for first image will be always called but for other images it will be sometimes called and sometimes doesn’t. Have I implemented it in wrong way or am I missing something. I have used latest Picasso along with okHttp 1.2.1.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JakeWhartoncommented, Sep 11, 2013

You need to hold a strong reference to targets yourself.

            CustomTarget target = new CustomTarget(imageView, progressBar,
                    index);
            picasso.load(imageUrl).into(target);

after this line target has nothing referencing it so it will be garbaged collected.

0reactions
laaptucommented, Nov 26, 2013

@hakimrie : Thanks for mentioning. I have updated the variable index now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Once = true attribute for Targets to allow target only executed ...
MSBuild is project oriented and within a project a target will only run once. Having a Once attribute on Target doesn't make sense....
Read more >
Event listeners not working? 3 key areas to troubleshoot
Events are dispatched by specific elements (their target ). Code can then add listeners to run custom logic in response. But it's not...
Read more >
How to modify environment variables passed to custom ...
A portable way of setting environment variables for a custom target is to use CMake's command-line tool mode command env :.
Read more >
target_sources() doesn't recognise GENERATED property for ...
When a target in another directory references it there is no GENERATED mark in the other directory. Some non-trivial refactoring and likely a ......
Read more >
4 Reasons Your Facebook Ads Don't Convert (and How to Fix ...
One of the main reasons marketers fail with Facebook Ads is because they fail to target their ads properly. Facebook allows you to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found