Android 如何在类ASyncTask中操作映像而不阻塞UI线程?

Android 如何在类ASyncTask中操作映像而不阻塞UI线程?,android,android-asynctask,Android,Android Asynctask,我的代码如下: private ImageView imageAvatar; private Drawable image; private BitmapDrawable drawable; protected Bitmap doInBackground(Void... params) { // TODO Auto-generated method stub String url = "https://graph.facebook.com/" + userId + "/pict

我的代码如下:

private ImageView imageAvatar;
private Drawable image;
private BitmapDrawable drawable;

protected Bitmap doInBackground(Void... params) {
    // TODO Auto-generated method stub
    String url = "https://graph.facebook.com/" + userId + "/picture?width=" + width + "&height=" + height;
    image = ImageOperations(url);
    imageAvatar.setImageDrawable(image);
    imageAvatar.setMinimumHeight(32);
    imageAvatar.setMinimumWidth(32);
    imageAvatar.setMaxHeight(128);
    imageAvatar.setMaxWidth(128);
    IsFinish = true;
    drawable = (BitmapDrawable) imageAvatar.getDrawable();
    if(drawable != null) {
        return drawable.getBitmap();
    }
    return null;
}
我通过
taskImage.execute().get()
检索数据。我知道
get()
将在必要时等待计算。我必须在
onPostExecute()
上实现我的代码,以防止阻塞UI线程

问题是:如果我想在
onPostExecute()
中操作代码以防止阻塞UI线程,结果不应该是
Bitmap
,而是想从
ASyncTask
中检索
Bitmap


我应该怎么做?

位图
结果存储在成员变量中?使用
get()
,会阻塞UI线程,因此不能以这种方式执行。如果不知道要实现什么目标,很难帮助您。您需要将代码放入onPostExecute方法中,并在不调用get method的情况下启动ASyncTask。您的意思是我必须使用
taskimage.execute()
,如何从
ASyncTask
获取数据?@barssala:当后台执行完成时,您将以位图的形式在onPostExecute方法中获取数据,只需将代码移到onPostExecute中即可