public class MYTask extends AsyncTask {
/**
* 表示任務執行之前的操作
*/
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog.show();
}
/**
* 主要是完成耗時的操作
*/
@Override
protected Bitmap doInBackground(String... arg0) {
// TODO Auto-generated method stub
// 使用網絡連接類HttpClient類王城對網絡數據的提取
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(arg0[0]);
Bitmap bitmap = null;
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
HttpEntity httpEntity = httpResponse.getEntity();
byte[] data = EntityUtils.toByteArray(httpEntity);
bitmap = BitmapFactory
.decodeByteArray(data, 0, data.length);
}
} catch (Exception e) {
// TODO: handle exception
}
return bitmap;
}
/**
* 主要是更新UI的操作
*/
@Override
protected void onPostExecute(Bitmap result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
imageView.setImageBitmap(result);
dialog.dismiss();
}
}
http://blog.csdn.net/easy_gemini/article/details/8219942