I am parsing a JSON Obj to get the url of an image. I am using this code.
private Drawable LoadImageFromWebOperations(String strPhotoUrl) {
try {
InputStream is = (InputStream) new URL(strPhotoUrl).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
Log.e("TAGG", strPhotoUrl);
return d;
} catch (Exception e) {
Log.e("TAGG", e.toString());
return null;
}
}
But I get an error that this must be done in an AsyncTask,i.e., Different Thread. But then how will I insert the drawable in an ImageView? Since DoInBackground() dosen't have access to UI elements. Also I don't have access to the URL until I parse the JSON obj I get the URL from. So what solution can I use in my situation. Thanks!
ListViewandRecyclerView, and so on. Libraries have implementations of all of that, written by Android experts, that have been tested by those experts and thousands of other Android developers through the use of those libraries. If you think that you can do better than that for your use case, feel free to implement yet another set of image-loading code for your own use.