Picasso Load Image into Target

前端 未结 2 1923
忘掉有多难
忘掉有多难 2020-12-17 03:17

I\'m using Picasso to download various images. Usually, I just display these in an ImageView but in this situation, I want to hold a strong reference to them so

相关标签:
2条回答
  • 2020-12-17 04:01

    Picasso holds Target instance with a weak reference, So your Target seems to be garbage collected.
    see: https://github.com/square/picasso/issues/352

    It is better to hold Target as an instance field.

    public class MapLayer {
    
        ...
    
        private Target target;
    
        private void downloadIcon() {
    
            ...
    
            target = new Target() {
                ...
            };
    
            ImageDownloader.getSharedInstance().load(url).into(target);
        }
    }
    
    0 讨论(0)
  • 2020-12-17 04:03

    Its because Picasso only keeps a weak reference to the Target object.

    If you want to have a strong reference I'd recommend tagging the Target to the View.
    Here is a solution for your problem.

    0 讨论(0)
提交回复
热议问题