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
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);
}
}
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.