就是调用异步类onPreExecute()doInBackground()方法执行完之后,onPostExecute()就不执行了。
解决方案 »
- 开发中如何如何解决 已安装了存在签名冲突的同名数据包
- java.lang.NoClassDefFoundError: com.sun.crypto.provider.SunJCE
- TextView放在ImageView下部(是imageview里面),大家是怎么做的
- android sdk 里的sip demo 问题
- 关于android访问本地mysql数据库
- 用java编写webservice,并使用ksoap2 for android 调用WebService
- Android查看Proxy是否设置成功
- 求基于android平台的飞信系统的代码
- 自定义view的问题,明白的进来看看
- 救火 选择Ophone的10个理由
- 初学android,看了很多书还是没发现该怎么处理网页??给个代码吧
- 有一个关于“Android SAX解析XML”的问题
private Context mContext; // reference to the calling Activity
int progress = -1;
Bitmap downloadedImage = null; DownloadImageTask(Context context) {
mContext = context;
} // Called from main thread to re-attach
protected void setContext(Context context) {
mContext = context;
if(progress >= 0) {
publishProgress(this.progress);
}
} protected void onPreExecute() {
progress = 0;
// We could do some other setup work here before doInBackground() runs
}
protected Bitmap doInBackground(String... urls) {
Log.v("doInBackground", "doing download of image...");
return downloadImage(urls);
} protected void onProgressUpdate(Integer... progress) {
TextView mText = (TextView)
((Activity) mContext).findViewById(R.id.text);
mText.setText("Progress so far: " + progress[0]);
} protected void onPostExecute(Bitmap result) {
if(result != null) {
downloadedImage = result;
setImageInView();
}
else {
TextView errorMsg = (TextView)
((Activity) mContext).findViewById(R.id.errorMsg);
errorMsg.setText("Problem downloading image. Please try later.");
}
} public Bitmap downloadImage(String... urls)
{
HttpClient httpClient = CustomHttpClient.getHttpClient();
try {
HttpGet request = new HttpGet(urls[0]);
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setSoTimeout(params, 60000); // 1 minute
request.setParams(params); setProgress(25); HttpResponse response = httpClient.execute(request); setProgress(50); sleepFor(5000); // five second sleep byte[] image = EntityUtils.toByteArray(response.getEntity()); setProgress(75); Bitmap mBitmap = BitmapFactory.decodeByteArray(image, 0, image.length); setProgress(100); return mBitmap;
} catch (IOException e) {
// covers:
// ClientProtocolException
// ConnectTimeoutException
// ConnectionPoolTimeoutException
// SocketTimeoutException
e.printStackTrace();
}
return null;
} private void setProgress(int progress) {
this.progress = progress;
publishProgress(this.progress);
} protected void setImageInView() {
if(downloadedImage != null) {
ImageView mImage = (ImageView)
((Activity) mContext).findViewById(R.id.image);
mImage.setImageBitmap(downloadedImage);
}
} private void sleepFor(long msecs) {
try {
Thread.sleep(msecs);
} catch (InterruptedException e) {
Log.v("sleep", "interrupted");
}
}
}