我正在使用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;
}
}
}
謝謝。