How to download an Image from a URL with an Asynctask

Hello little Androids!

Loading image from the Internet is a very common issue in Android. But don’t fall to the common mistake of doing it in the UI thread… You should use an Asyncronous Task! (Asynctask or a loader, depending on what you want).

public 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 mIcon11 = null;
        try {
            InputStream in = new;
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
        return mIcon11;
    protected void onPostExecute(Bitmap result) {

I have found the code in the following link:

Bye byeee! ^^


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s