I am attempting to use Picasso to get three Bitmap
images from a URL
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab2);
Drawable d1 = new BitmapDrawable(Picasso.with(Tab2.this).load(zestimateImg1).get());
}
I am getting FATAL EXCEPTION
with this code. I suspect it has to do with the fact that this should be done within AsyncTask
, but I can't get it to work. If using that is avoidable, I would like to do this without using AsyncTask
.
How can I get this code to run without crashing?
If the best way to do this is with AsyncTask
, then that solution is ok.
You cannot make synchronous requests in the main thread. If you dont want to use an AsyncThread then just use Picasso together with a Target.
I recommend you save a reference to your target like so:
This is because Picasso uses weak references to them and they might be garbage collected before the process is finished.
Just for the record:
Source: http://square.github.io/picasso/
onPrepareLoad()
is called always after starting the request.from
can be "DISK", "MEMORY" or "NETWORK" to indicate where was the image obtained from.None of above worked for me instead this
Hope it may be useful for someone