Loopj AsyncHttpResponseHandler存储onSuccess响应

时间:2014-01-24 15:17:14

标签: java android loopj android-async-http

我尝试将AsyncHttpResponseHandler的响应字符串存储在类变量中,如下所示:

public boolean isLatestVersion = true;

private void requestServerVersionFile() {
    AsyncHttpClient client = new AsyncHttpClient();
    client.get(appVersionCheckUrl, new AsyncHttpResponseHandler() {

        @Override
        public void onSuccess(String appVersionCodeServer) {
            Log.e(LOG_TAG, appVersionCheckUrl + " = " + appVersionCodeServer);
            int iResponse = Integer.parseInt(appVersionCodeServer.trim());
            if(iResponse > appVersionCode)
            {
                isLatestVersion = false; //<<< tried this. and self. before
            }
        }

    });
}

...但 isLatestVersion保持正确。 覆盖此变量的正确/最明智的方法是什么?

1 个答案:

答案 0 :(得分:0)

我使用嵌套类(http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html

解决了这些问题