Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用loopj android async检查异步请求是否完成_Android_Asynchronous_Get - Fatal编程技术网

使用loopj android async检查异步请求是否完成

使用loopj android async检查异步请求是否完成,android,asynchronous,get,Android,Asynchronous,Get,我正在开发一个使用android异步的android应用程序。我正在使用这个名为 我为GET请求创建了一个方法 public String getVenues(String token) throws Exception { AsyncHttpClient venuesReq = new AsyncHttpClient(); venuesReq.addHeader("Authorization", "Token token=" + token); venuesReq.ge

我正在开发一个使用android异步的android应用程序。我正在使用这个名为

我为GET请求创建了一个方法

public String getVenues(String token) throws Exception {
    AsyncHttpClient venuesReq = new AsyncHttpClient();
    venuesReq.addHeader("Authorization", "Token token=" + token);
    venuesReq.get(mainAct.httpRequestURL + "/venues", new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(String response) {
            venues = response;
        }
        @Override
        public void onFinish() {
           // Completed the request (either success or failure)
       }
    return venues;
}
但是当我调用
getVinces(“token”)
时,返回值为空,但当我尝试在几秒钟后调用
getVinces(“token”)
时,现在有场馆的结果

我知道我正在使用异步请求,所以场馆不会立即返回


现在我想要的是,当我调用
getVinces(“token”)
方法时,应该有一个GET请求的返回响应。

您需要使用这里的接口看看这个

您正在侦听/请求asyntask结果的类需要实现接口并从asyntask调用该接口方法


希望这有帮助

只有当您有一个扩展AsyncTask的类时,该解决方案才有效,但我已经在片段上扩展了我的类。不,您也可以使用片段来实现该解决方案。检查此链接公共静态类FragmentA扩展ListFragment{OnArticleSelectedListener mListener;..@Override public void onatAch(活动){super.onatAch(活动);try{mListener=(OnArticleSelectedListener)活动;}catch(ClassCastException e){抛出新的ClassCastException(activity.toString()+“必须在ArticleSelectedListener上实现”);}}…}