Skip to content

Instantly share code, notes, and snippets.

@crossphd
Created February 21, 2018 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crossphd/a4b03e3667f690ef1f35c6caff1de866 to your computer and use it in GitHub Desktop.
Save crossphd/a4b03e3667f690ef1f35c6caff1de866 to your computer and use it in GitHub Desktop.
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap bmp = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
bmp = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return bmp;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment