Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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();
    }
share|improve this question
 
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. –  bagusflyer Jan 24 at 0:59
add comment

2 Answers

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

share|improve this answer
add comment
HttpClient httpClient = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 30000); //Timeout Limit
share|improve this answer
 
Did you even read my question? How does this apply to asynchttpclient? –  ChuckKelly Jan 15 at 6:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.