我试图在loopj上使用setusesynchronousmode来等待http调用的结果,然后在一种情况下继续。我试过:
AsyncHttpResponseHandler responseHandler = new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
Log.d("TEST", "Got results");
}
};
AsyncHttpClient client = new AsyncHttpClient();
responseHandler.setUseSynchronousMode(true);
client.get("http://www.google.com", responseHandler);
Log.d("TEST", "Don't want to get here until after getting results");
但结果是:
07-11 19:48:05.631 D/TEST﹕ Don't want to get here until after getting results
07-11 19:48:05.814 D/TEST﹕ Got results
我是不是误解了setuseconchronousmode应该做什么?
最佳答案
你应该用SyncHttpClient
而不是AsyncHttpClient
。setUseSynchronousMode
对AsyncHttpClient
没有理想的效果。