3

I'm using loopj 1.4.4 library to make HTTP request on my android device with 4.2.2. setTimeout method is not working as expected:

public class RestClient {
    private static final int CONNECTION_TIMEOUT = 1000;

    private static AsyncHttpClient client = new AsyncHttpClient();

    public static void get(String url, RequestParams params,
            AsyncHttpResponseHandler responseHandler) {

        client.setTimeout(CONNECTION_TIMEOUT);

        client.setMaxRetriesAndTimeout(1, CONNECTION_TIMEOUT);

        client.get(getAbsoluteUrl(url), params, responseHandler);
    }

    private static String getAbsoluteUrl(String relativeUrl) {
        return Config.API_URL + relativeUrl;
    }
}

Using the code above I receive a timeout (specifically a onFailure callback) after more or less 40 seconds...where am I wrong? I think my code is not very different from this one: Loopj's AsyncHttpclient not setting the correct timeout

5
  • 1
    I guess setTimeout and setMaxRetriesAndTimeout set two different timeouts, of course you need to set it using setTimeout but 1 second I think is really low... did you try with 10 seconds (default value)? Same behavior?
    – fasteque
    Jan 22, 2014 at 15:15
  • Seems like the value I set is not considered. Always 40 seconds to failure.
    – Jumpa
    Jan 22, 2014 at 15:25
  • Did you check all the onFailure methods? Could you please also post a logcat where you print a message when you make the request and then a message for each of the success/failure methods? Thanks a lot.
    – fasteque
    Jan 22, 2014 at 15:30
  • same exact problem. Any solution?
    – Alexis
    Apr 20, 2014 at 1:34
  • I just ended using the default 10000 value and removing setMaxRetriesAndTimeout...also be sure to override the onFailure(Throwable e, String response) method of the library.
    – Jumpa
    Apr 20, 2014 at 8:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.