4

im using the Asynchronous Http Client that can be found here: http://loopj.com/android-async-http/

and it works great besides about 1 out of every 10 or so requests I make end up giving me a infinite progress dialog which I believe means for whatever reason no response of any kind is being returned because I have written code to dismiss the dialog in onSuccess AND onFailure so im a bit confused how this could happen.

Here is my code that sets up the request:

  public static void post(String token,String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
     Log.i(token,"token");
      client.addHeader("token", token);
      client.setTimeout(3000);
      client.post(url, params, responseHandler);


  }

And here is where i override onSuccess and onFailure:

@Override
            public void onFailure(Throwable arg0, String arg1) {
                // TODO Auto-generated method stub
                super.onFailure(arg0, arg1);
                pdialog.dismiss();
                Log.i("failed to login", arg1.toString());
                Toast.makeText(getActivity(), arg1.toString() , Toast.LENGTH_LONG).show();
            }

            @Override
            public void onSuccess(final JSONObject json) {
                pdialog.dismiss();
    }
1
  • Have you solved the problem? I encountered the same issue. Sometimes it just hang there. No onFailure or onSuccess callback even after I set the timeout. Commented Jan 24, 2014 at 0:59

2 Answers 2

2

The library seems to be doing what you want it to do, setTimeout code from the AsyncHttpClient class

public void setTimeout(int timeout){
    final HttpParams httpParams = this.httpClient.getParams();
    ConnManagerParams.setTimeout(httpParams, timeout);
    HttpConnectionParams.setSoTimeout(httpParams, timeout);
    HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
}

If it is not working then better report the issue here

Sign up to request clarification or add additional context in comments.

Comments

0

After much frustration I gave up on figuring this out BUT the latest version DOES make it very easy to accomplish this if you just upgrade your lib.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.