Android AsyncTask 详解
2010-11-05 00:55:35 来源:WEB开发网ImageView imageView01;
TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) this.findViewById(R.id.TextView01);
imageView01 = (ImageView) this.findViewById(R.id.ImageView01);
GetImage getImage = new GetImage();
getImage.execute("http://hi.csdn.net/attachment/201010/27/0_1288149117Yk8W.gif");
}
private class GetImage extends AsyncTask {
public GetImage() {
super();
// TODO Auto-generated constructor stub
}
@Override
protected void onCancelled() {
Log.i("czb", "onCancelled is running...");
super.onCancelled();
}
@Override
protected void onPostExecute(Object result) {
/*
* 此方法在主线程执行,任务执行的结果作为此方法的参数返回
*/
Log.i("czb", "onPostExecute is running...");
Log.i("czb", "result == null ? " + (result == null));
imageView01.setImageBitmap((Bitmap)result);
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
/*
* 执行预处理,它运行于UI线程,可以为后台任务做一些准备工作,比如绘制一个进度条控件
*/
Log.i("czb", "onPreExecute is running...");
super.onPreExecute();
}
@Override
protected void onProgressUpdate(Object... values) {
/*
* 此方法在主线程执行,用于显示任务执行的进度。
*/
Log.i("czb", "onProgressUpdate is running...");
// 由publishProgress传递的值
Log.i("czb", "values " + values[0]);
super.onProgressUpdate(values);
}
@Override
protected Object doInBackground(Object... params) {
更多精彩
赞助商链接