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

时间:2014-03-25 10:35:53

标签: android asynchronous get

我正在开发一款使用Android Async的Android应用。我正在使用名为Android Asynchronous Http Client

的库

我为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;
}

但是当我调用getVenues("token")时返回为空,但是当我尝试在几秒钟后调用getVenues("token")时,现在会有场地的结果。

我知道我正在使用异步请求,因此场地不会立即返回。

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

1 个答案:

答案 0 :(得分:1)

你需要在这里使用界面看看这个

https://stackoverflow.com/a/21773406/472336

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

希望这有帮助

相关问题