Java 如何将对象从asynctask返回到android中的主类

Java 如何将对象从asynctask返回到android中的主类,java,android,android-asynctask,Java,Android,Android Asynctask,我想将文档返回到我的主类,但即使使用全局变量dosen也不起作用,这是因为asynctask没有完成任务。我想是否有一个解决方案来获取对象表单asynctask? 我已经在onPostExecute中尝试了这种矫揉造作的方式,但是如果我在asynctask之外,对象将变为null 这是一节课: private class RequestTask extends AsyncTask<String, Void, Document> { protected Document

我想将文档返回到我的主类,但即使使用全局变量dosen也不起作用,这是因为asynctask没有完成任务。我想是否有一个解决方案来获取对象表单asynctask? 我已经在onPostExecute中尝试了这种矫揉造作的方式,但是如果我在asynctask之外,对象将变为null 这是一节课:

    private class RequestTask extends AsyncTask<String, Void, Document> {
    protected Document doInBackground(String... url) {
        try {
            HttpClient httpClient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            HttpPost httpPost = new HttpPost(url[0]);
            HttpResponse response = httpClient.execute(httpPost,
                    localContext);
            InputStream in = response.getEntity().getContent();
            DocumentBuilder builder = DocumentBuilderFactory.newInstance()
                    .newDocumentBuilder();

            return builder.parse(in);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        }

        return null;
    }

    protected void onPostExecute(Document doc) {
        super.onPostExecute(doc);

        if (mDirectionListener != null) {
            mDirectionListener.onResponse(getStatus(doc), doc,
                    GoogleDirection.this);
        }
    }

    private String getStatus(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("status");
        Node node1 = nl1.item(0);

        if (isLogging) {
            Log.i("GoogleDirection", "Status : " + node1.getTextContent());
        }

        return node1.getTextContent();
    }
}
私有类RequestTask扩展了AsyncTask{
受保护文档doInBackground(字符串…url){
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
HttpContext localContext=新的BasicHttpContext();
HttpPost HttpPost=新的HttpPost(url[0]);
HttpResponse response=httpClient.execute(httpPost,
本地上下文);
InputStream in=response.getEntity().getContent();
DocumentBuilder=DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
返回builder.parse(in);
}捕获(IOE异常){
e、 printStackTrace();
}捕获(ParserConfiguration异常e){
e、 printStackTrace();
}捕获(SAXE异常){
e、 printStackTrace();
}
返回null;
}
后期执行时受保护的无效(文档文档){
super.onPostExecute(doc);
if(mDirectionListener!=null){
mDirectionListener.onResponse(getStatus(doc)、doc、,
谷歌(GoogleDirection.this);
}
}
私有字符串getStatus(文档文档){
NodeList nl1=doc.getElementsByTagName(“状态”);
节点node1=nl1。项(0);
如果(isLogging){
Log.i(“谷歌方向”,“状态:+node1.getTextContent());
}
返回node1.getTextContent();
}
}
我尝试了这么多的解决方案,但没有一个有效。。。请帮帮我

更新: 我得到一些错误:

我的代码的结构: ClassMain、GoogleDirection和innerClass是异步任务

这是我的第一个包含内部类(Asynctask)的类 包com.example.busmapsprroject.app

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.AsyncTask;
import android.util.DisplayMetrics;
import android.util.Log;

import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.PolylineOptions;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;


@SuppressLint("NewApi")
public class GoogleDirection {
    public final static String MODE_WALKING = "walking";
    private OnDirectionResponseListener mDirectionListener = null;
    private boolean isLogging = false;
    private Context myContext = null;
    private Document test;

    public GoogleDirection(Context context) {
        myContext = context;
    }

    public String request(LatLng start, LatLng end, String mode) {
        final String url = "http://maps.googleapis.com/maps/api/directions/xml?" +
            "origin=" + start.latitude + "," + start.longitude +
            "&destination=" + end.latitude + "," + end.longitude +
            "&sensor=false&units=metric&mode=" + mode;

        if (isLogging) {
            //Display information in logcat (report success)
            Log.i("GoogleDirection", "URL : " + url);
        }

            new RequestTask().execute(url);


        return url;
    }

    public void setLogging(boolean state) {
        isLogging = state;
    }

    public String getStatus(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("status");
        Node node1 = nl1.item(0);

        if (isLogging) {
            Log.i("GoogleDirection", "Status : " + node1.getTextContent());
        }

        return node1.getTextContent();
    }

    public String[] getDurationText(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("duration");
        String[] arr_str = new String[nl1.getLength() - 1];

        for (int i = 0; i < (nl1.getLength() - 1); i++) {
            Node node1 = nl1.item(i);
            NodeList nl2 = node1.getChildNodes(); //Return child of a node (Duration have text and value)
            Node node2 = nl2.item(getNodeIndex(nl2, "text"));
            arr_str[i] = node2.getTextContent();

            if (isLogging) {
                Log.i("GoogleDirection",
                    "DurationText : " + node2.getTextContent());
            }
        }

        return arr_str;
    }

    public int[] getDurationValue(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("duration");
        int[] arr_int = new int[nl1.getLength() - 1];

        for (int i = 0; i < (nl1.getLength() - 1); i++) {
            Node node1 = nl1.item(i);
            NodeList nl2 = node1.getChildNodes();
            Node node2 = nl2.item(getNodeIndex(nl2, "value"));
            arr_int[i] = Integer.parseInt(node2.getTextContent());

            if (isLogging) {
                Log.i("GoogleDirection", "Duration : " +
                    node2.getTextContent());
            }
        }

        return arr_int;
    }

    public String getTotalDurationText(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("duration");
        Node node1 = nl1.item(nl1.getLength() - 1);
        NodeList nl2 = node1.getChildNodes();
        Node node2 = nl2.item(getNodeIndex(nl2, "text"));

        if (isLogging) {
            Log.i("GoogleDirection", "TotalDuration : " +
                node2.getTextContent());
        }

        return node2.getTextContent();
    }

    public int getTotalDurationValue(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("duration");
        Node node1 = nl1.item(nl1.getLength() - 1);
        NodeList nl2 = node1.getChildNodes();
        Node node2 = nl2.item(getNodeIndex(nl2, "value"));

        if (isLogging) {
            Log.i("GoogleDirection", "TotalDuration : " +
                node2.getTextContent());
        }
        return Integer.parseInt(node2.getTextContent());
    }

    public String[] getDistanceText(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("distance");
        String[] arr_str = new String[nl1.getLength() - 1];

        for (int i = 0; i < (nl1.getLength() - 1); i++) {
            Node node1 = nl1.item(i);
            NodeList nl2 = node1.getChildNodes();
            Node node2 = nl2.item(getNodeIndex(nl2, "text"));
            arr_str[i] = node2.getTextContent();

            if (isLogging) {
                Log.i("GoogleDirection",
                    "DurationText : " + node2.getTextContent());
            }
        }

        return arr_str;
    }

    public int[] getDistanceValue(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("distance");
        int[] arr_int = new int[nl1.getLength() - 1];

        for (int i = 0; i < (nl1.getLength() - 1); i++) {
            Node node1 = nl1.item(i);
            NodeList nl2 = node1.getChildNodes();
            Node node2 = nl2.item(getNodeIndex(nl2, "value"));
            arr_int[i] = Integer.parseInt(node2.getTextContent());

            if (isLogging) {
                Log.i("GoogleDirection", "Duration : " +
                    node2.getTextContent());
            }
        }

        return arr_int;
    }

    public String getTotalDistanceText(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("distance");
        Node node1 = nl1.item(nl1.getLength() - 1);
        NodeList nl2 = node1.getChildNodes();
        Node node2 = nl2.item(getNodeIndex(nl2, "text"));

        if (isLogging) {
            Log.i("GoogleDirection", "TotalDuration : " +
                node2.getTextContent());
        }

        return node2.getTextContent();
    }

    public int getTotalDistanceValue(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("distance");
        Node node1 = nl1.item(nl1.getLength() - 1);
        NodeList nl2 = node1.getChildNodes();
        Node node2 = nl2.item(getNodeIndex(nl2, "value"));

        if (isLogging) {
            Log.i("GoogleDirection", "TotalDuration : " +
                node2.getTextContent());
        }

        return Integer.parseInt(node2.getTextContent());
    }

    public String getStartAddress(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("start_address");
        Node node1 = nl1.item(0);

        if (isLogging) {
            Log.i("GoogleDirection", "StartAddress : " +
                node1.getTextContent());
        }

        return node1.getTextContent();
    }

    public String getEndAddress(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("end_address");
        Node node1 = nl1.item(0);

        if (isLogging) {
            Log.i("GoogleDirection", "StartAddress : " +
                node1.getTextContent());
        }

        return node1.getTextContent();
    }

    public String getCopyRights(Document doc) {
        NodeList nl1 = doc.getElementsByTagName("copyrights");
        Node node1 = nl1.item(0);

        if (isLogging) {
            Log.i("GoogleDirection", "CopyRights : " + node1.getTextContent());
        }

        return node1.getTextContent();
    }

    public ArrayList<LatLng> getDirection(Document doc) {
        NodeList nl1;
        NodeList nl2;
        NodeList nl3;
        ArrayList<LatLng> listGeopoints = new ArrayList<LatLng>();
        nl1 = doc.getElementsByTagName("step");

        if (nl1.getLength() > 0) {
            for (int i = 0; i < nl1.getLength(); i++) {
                Node node1 = nl1.item(i);
                nl2 = node1.getChildNodes();

                Node locationNode = nl2.item(getNodeIndex(nl2, "start_location"));
                nl3 = locationNode.getChildNodes();

                Node latNode = nl3.item(getNodeIndex(nl3, "lat"));
                double lat = Double.parseDouble(latNode.getTextContent());
                Node lngNode = nl3.item(getNodeIndex(nl3, "lng"));
                double lng = Double.parseDouble(lngNode.getTextContent());
                listGeopoints.add(new LatLng(lat, lng));

                locationNode = nl2.item(getNodeIndex(nl2, "polyline"));
                nl3 = locationNode.getChildNodes();
                latNode = nl3.item(getNodeIndex(nl3, "points"));

                ArrayList<LatLng> arr = decodePoly(latNode.getTextContent());

                for (int j = 0; j < arr.size(); j++) {
                    listGeopoints.add(new LatLng(arr.get(j).latitude,
                            arr.get(j).longitude));
                }

                locationNode = nl2.item(getNodeIndex(nl2, "end_location"));
                nl3 = locationNode.getChildNodes();
                latNode = nl3.item(getNodeIndex(nl3, "lat"));
                lat = Double.parseDouble(latNode.getTextContent());
                lngNode = nl3.item(getNodeIndex(nl3, "lng"));
                lng = Double.parseDouble(lngNode.getTextContent());
                listGeopoints.add(new LatLng(lat, lng));
            }
        }

        return listGeopoints;
    }

    public ArrayList<LatLng> getSection(Document doc) {
        NodeList nl1;
        NodeList nl2;
        NodeList nl3;
        ArrayList<LatLng> listGeopoints = new ArrayList<LatLng>();
        nl1 = doc.getElementsByTagName("step");

        if (nl1.getLength() > 0) {
            for (int i = 0; i < nl1.getLength(); i++) {
                Node node1 = nl1.item(i);
                nl2 = node1.getChildNodes();

                Node locationNode = nl2.item(getNodeIndex(nl2, "end_location"));
                nl3 = locationNode.getChildNodes();

                Node latNode = nl3.item(getNodeIndex(nl3, "lat"));
                double lat = Double.parseDouble(latNode.getTextContent());
                Node lngNode = nl3.item(getNodeIndex(nl3, "lng"));
                double lng = Double.parseDouble(lngNode.getTextContent());
                listGeopoints.add(new LatLng(lat, lng));
            }
        }

        return listGeopoints;
    }

    public PolylineOptions getPolyline(Document doc, int width, int color) {
        ArrayList<LatLng> arr_pos = getDirection(doc);
        PolylineOptions rectLine = new PolylineOptions().width(dpToPx(width))
                                                        .color(color);

        for (int i = 0; i < arr_pos.size(); i++)
            rectLine.add(arr_pos.get(i));

        return rectLine;
    }

    private int getNodeIndex(NodeList nl, String nodename) {
        for (int i = 0; i < nl.getLength(); i++) {
            if (nl.item(i).getNodeName().equals(nodename)) {
                return i;
            }
        }

        return -1;
    }

    private ArrayList<LatLng> decodePoly(String encoded) {
        ArrayList<LatLng> poly = new ArrayList<LatLng>();
        int index = 0;
        int len = encoded.length();
        int lat = 0;
        int lng = 0;

        while (index < len) {
            int b;
            int shift = 0;
            int result = 0;

            do {
                b = encoded.charAt(index++) - 63;
                result |= ((b & 0x1f) << shift);
                shift += 5;
            } while (b >= 0x20);

            int dlat = (((result & 1) != 0) ? (~(result >> 1)) : (result >> 1));
            lat += dlat;
            shift = 0;
            result = 0;

            do {
                b = encoded.charAt(index++) - 63;
                result |= ((b & 0x1f) << shift);
                shift += 5;
            } while (b >= 0x20);

            int dlng = (((result & 1) != 0) ? (~(result >> 1)) : (result >> 1));
            lng += dlng;

            LatLng position = new LatLng((double) lat / 1E5, (double) lng / 1E5);
            poly.add(position);
        }

        return poly;
    }

    //Convert dp to pixel
    private int dpToPx(int dp) {
        DisplayMetrics displayMetrics = myContext.getResources()
                                                 .getDisplayMetrics();
        int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));

        return px;
    }

    public void setOnDirectionResponseListener(
        OnDirectionResponseListener listener) {
        mDirectionListener = listener;
    }

    public interface OnDirectionResponseListener {
        public void onResponse(String status, Document doc, GoogleDirection gd);
    }

    private class RequestTask extends AsyncTask<String, Void, Document> {

        protected Document doInBackground(String... url) {
            try {
                HttpClient httpClient = new DefaultHttpClient();
                HttpContext localContext = new BasicHttpContext();
                HttpPost httpPost = new HttpPost(url[0]);
                HttpResponse response = httpClient.execute(httpPost,
                        localContext);
                InputStream in = response.getEntity().getContent();
                DocumentBuilder builder = DocumentBuilderFactory.newInstance()
                                                                .newDocumentBuilder();

                return builder.parse(in);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            }

            return null;
        }

        protected void onPostExecute(Document doc) {
            super.onPostExecute(doc);

            if (mDirectionListener != null) {
                mDirectionListener.onResponse(getStatus(doc), doc,
                    GoogleDirection.this);
            }
        }


        private String getStatus(Document doc) {
            NodeList nl1 = doc.getElementsByTagName("status");
            Node node1 = nl1.item(0);

            if (isLogging) {
                Log.i("GoogleDirection", "Status : " + node1.getTextContent());
            }

            return node1.getTextContent();
        }
    }
}
导入android.annotation.SuppressLint;
导入android.content.Context;
导入android.os.AsyncTask;
导入android.util.DisplayMetrics;
导入android.util.Log;
导入com.google.android.gms.maps.model.LatLng;
导入com.google.android.gms.maps.model.PolylineOptions;
导入org.apache.http.HttpResponse;
导入org.apache.http.client.HttpClient;
导入org.apache.http.client.methods.HttpPost;
导入org.apache.http.impl.client.DefaultHttpClient;
导入org.apache.http.protocol.BasicHttpContext;
导入org.apache.http.protocol.HttpContext;
导入org.w3c.dom.Document;
导入org.w3c.dom.Node;
导入org.w3c.dom.NodeList;
导入org.xml.sax.SAXException;
导入java.io.IOException;
导入java.io.InputStream;
导入java.util.ArrayList;
导入javax.xml.parsers.DocumentBuilder;
导入javax.xml.parsers.DocumentBuilderFactory;
导入javax.xml.parsers.parserConfiguration异常;
@SuppressLint(“新API”)
公共类谷歌指南{
公共最终静态字符串模式\u WALKING=“WALKING”;
private OnDirectionResponseListener mDirectionListener=null;
私有布尔isLogging=false;
私有上下文myContext=null;
私人文件测试;
公共谷歌方向(上下文){
myContext=上下文;
}
公共字符串请求(LatLng开始、LatLng结束、字符串模式){
最终字符串url=”http://maps.googleapis.com/maps/api/directions/xml?" +
“origin=“+start.latitude+”,“+start.longitude”+
“&destination=“+end.latitude+”,“+end.longitude”+
“&sensor=false&units=metric&mode=“+mode;
如果(isLogging){
//在logcat中显示信息(报告成功)
Log.i(“谷歌方向”,“URL:+URL”);
}
新建RequestTask().execute(url);
返回url;
}
公共void setLogging(布尔状态){
isLogging=状态;
}
公共字符串getStatus(文档文档){
NodeList nl1=doc.getElementsByTagName(“状态”);
节点node1=nl1。项(0);
如果(isLogging){
Log.i(“谷歌方向”,“状态:+node1.getTextContent());
}
返回node1.getTextContent();
}
公共字符串[]getDurationText(文档文档){
NodeList nl1=doc.getElementsByTagName(“持续时间”);
String[]arr_str=新字符串[nl1.getLength()-1];
对于(int i=0;i<(nl1.getLength()-1);i++){
节点node1=nl1.项目(i);
NodeList nl2=node1.getChildNodes();//返回节点的子节点(持续时间包含文本和值)
节点node2=nl2.item(getNodeIndex(nl2,text));
arr_str[i]=node2.getTextContent();
如果(isLogging){
Log.i(“谷歌方向”,
“DurationText:+node2.getTextContent());
}
}
返回arr_str;
}
public int[]getDurationValue(文档文档){
NodeList nl1=doc.getElementsByTagName(“持续时间”);
int[]arr_int=new int[nl1.getLength()-1];
对于(int i=0;i<(nl1.getLength()-1);i++){
节点node1=nl1.项目(i);
NodeList nl2=node1.getChildNodes();
节点node2=nl2.item(getNodeIndex(nl2,value));
arr_int[i]=Integer.parseInt(node2.getTextContent());
如果(isLogging){
Log.i(“谷歌方向”,“持续时间:”+
node2.getTextContent());
}
}
返回arr_int;
}
公共字符串getTotalDurationText(文档文档){
NodeList nl1=doc.getElementsByTagName(“持续时间”);
节点node1=nl1.item(nl1.getLength()-1);
NodeList nl2=node1.getChildNodes();
节点node2=nl2.item(getNodeIndex(nl2,text));
如果(isLogging){
Log.i(“谷歌方向”,“Tot”
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import org.w3c.dom.Document;

public class MapsActivity extends FragmentActivity {

    private GoogleMap mMap; // Might be null if Google Play services APK is not available.
    private GoogleDirection gd;
    private LatLng Arret=new LatLng(30.413647, -9.555608);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        gd = new GoogleDirection(this);
        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    /**
     * Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly
     * installed) and the map has not already been instantiated.. This will ensure that we only ever
     * call {@link #setUpMap()} once when {@link #mMap} is not null.
     * <p>
     * If it isn't installed {@link SupportMapFragment} (and
     * {@link com.google.android.gms.maps.MapView MapView}) will show a prompt for the user to
     * install/update the Google Play services APK on their device.
     * <p>
     * A user can return to this FragmentActivity after following the prompt and correctly
     * installing/updating/enabling the Google Play services. Since the FragmentActivity may not
     * have been completely destroyed during this process (it is likely that it would only be
     * stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this
     * method in {@link #onResume()} to guarantee that it will be called.
     */
    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            mMap.setMyLocationEnabled(true);
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }

    /**
     * This is where we can add markers or lines, add listeners or move the camera. In this case, we
     * just add a marker near Africa.
     * <p>
     * This should only be called once and when we are sure that {@link #mMap} is not null.
     */
    private void setUpMap() {

        MyLocation loc=new MyLocation(this);
        mMap.addMarker(new MarkerOptions().position(new LatLng(loc.getLatitude(),loc.getLongitude()))
                .icon(BitmapDescriptorFactory.defaultMarker(
                        BitmapDescriptorFactory.HUE_BLUE)));
        mMap.addMarker(new MarkerOptions().position(Arret)
                .icon(BitmapDescriptorFactory.defaultMarker(
                        BitmapDescriptorFactory.HUE_BLUE)));
        gd.setOnDirectionResponseListener(new GoogleDirection.OnDirectionResponseListener() {
            @Override
            public void onResponse(String status, Document doc, GoogleDirection gd) {
                mMap.addPolyline(gd.getPolyline(doc, 3, Color.RED));
                gd.getTotalDurationValue(doc);
            }
        });
        gd.setLogging(true);
        //LatLng test=new LatLng((loc.getLatitude()+0.1f),(loc.getLongitude()+0.5f));
        gd.request(new LatLng(loc.getLatitude(),loc.getLongitude()), Arret , GoogleDirection.MODE_WALKING);

    }
}
public interface OnTaskCompleted{
    void onTaskCompleted(Document doc);
}
public YourActivity implements OnTaskCompleted{
   //your Activity
}
public YourTask extends AsyncTask<Object,Object,Object>{ 
private OnTaskCompleted listener;

// all your stuff
public YourTask(OnTaskCompleted listener){
    this.listener=listener;
}

protected void onPostExecute(Object o){
    listener.onTaskCompleted(doc);
}
}
private class RequestTask extends AsyncTask<String, Void, Document> {

  private MainClass myClass

  public RequestTask(MainClass myClass){
     this.myClass = myClass
  }

...

  protected void onPostExecute(Document doc) {
    super.onPostExecute(doc);
    myClass.myMethod(doc);
  }
...
}
    protected void onPostExecute(Document doc) {
        documentIsReady(doc);
    }

}

public void documentIsReady(Document doc)
{
    //Do somehting
}