0

我有以下三行代码。

Line 1 : GetBitMapFromURL gbmap = new GetBitMapFromURL();   //Obtain thumbnail bitmap
Line 2 : gbmap.execute(applicationThumbNailURL);
Line 3 : applicationThumbnailBitMap = gbmap.returnBitmap();

我希望仅在 GetBitMapFromURL 异步任务的 onPostExecute 执行后才执行第 3 行。

4

1 回答 1

3

在 GetBitMapFromURL 中创建回调。

public class GetBitMapFromURL extends AsyncTask<Void, Void, Void> {

    private GetBitMapFromURLCallback mCallback = null;

    public WebService(GetBitMapFromURLCallback callback) {
        mCallback = callback;
    }

    @Override
    protected Boolean doInBackground(Void... params) {
        // ...
    }

    @Override
    protected void onPostExecute(Boolean result) {
        super.onPostExecute(result);

        if (mCallback != null) {
            mCallback.onGetBitMapFromURLComplete(this);
        }
    }

    public interface GetBitMapFromURLCallback {

        public void onGetBitMapFromURLComplete(GetBitMapFromURL getBitMapFromUrl);
    }
}

public class MyActivity extends Activity implements GetBitMapFromURLCallback {

    // ...

    public void onGetBitMapFromURLComplete(GetBitMapFromURL getBitMapFromUrl) {
        // This code will get called the moment the AsyncTask finishes
    }
}

并让您的活动实现此回调和onGetBitMapFromURLComplete().

于 2012-10-31T16:42:26.617 回答