Q:

How to send an image from background thread to the UI thread using AsyncTask?

I'm using AsyncTask to download an image and want to send the downloaded image to the UI thread. Here is the code for it. 
public class DownloadImageTask extends AsyncTask<URL, Void, Drawable>{

    @Override
    protected Drawable doInBackground(URL... imgURL) {
        // TODO Auto-generated method stub
        InputStream in;
        Bitmap bitmap;
        Drawable d;
        try {
            //in = (InputStream) imgURL[0].getContent();
            bitmap = BitmapFactory.decodeStream(imgURL[0].openConnection().getInputStream());
             d =(Drawable)new BitmapDrawable(bitmap); 
             return d;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }       
    }
}   

Thanks.

A:

After doInBackround() is executed the returned value will be passed to onPostExecute() in your AsynkTask, so you should override the onPostExecute() method, and there you will receive your Drawable. Note that onPostExecute() and onPreExecute() are run on the UI Thread so you are able to modify/update the UI from this 2 methods.

