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();
}
}