就是调用异步类onPreExecute()doInBackground()方法执行完之后,onPostExecute()就不执行了。

解决方案 »

  1.   

    给你一个异步下载图片的demo。public class DownloadImageTask extends AsyncTask<String, Integer, Bitmap> {
    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");
    }
        }
    }
      

  2.   

    看看大家有没有遇到过,代码没有问题,别的项目都没有问题,只有这个项目里所有的Task类有这个问题,以前也没有问题滴。估计是项目该环境了.
      

  3.   

    小弟之前遇到同样问题~~~  解决办法  换了一种  异步加载   android 异步加载 貌似有 3-4种方法  Handler Runnable   == 
      

  4.   

    我也有类似的问题,大家帮帮忙:http://topic.csdn.net/u/20120514/10/87c07b17-385a-4b73-a789-18bed8a16630.html?83984