我正在使用AsyncTask下载图像,并希望将下载的图像发送到UI线程。这是它的代码。如何使用AsyncTask将图像从后台线程发送到UI线程?
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;
}
}
}
谢谢。