AsyncHttpClient does not run onSucces or onFailure

1

I execute the DNITaxistes method, but when I make the call, I do not execute the code of the onSuccess and neither the one of the onFailure , it directly exits the method. The searchTaxist method executes another asynchronous call. Any solution?

 public void DNITaxistes() {
    AsyncHttpClient client = new AsyncHttpClient();
    client.get(URL, new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            JSONArray dniTaxistes;
            String strResponseBody = new String(responseBody);

            try {
                dniTaxistes = new JSONArray(strResponseBody);
                for(int i=0; i < dniTaxistes.length(); i ++){
                    DNITaxistaTemporal = dniTaxistes.getString(i);
                    Log.d("DNI TAXISTA: ",""+ DNITaxistaTemporal);
                    buscarTaxista();
                }

            } catch (JSONException e) {
                Log.d("error",""+e);
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
            Log.d("ERROR STATUS:"," "+ statusCode);
        }

    });
}
    
asked by moraa 29.05.2018 в 00:27
source

1 answer

0

One reason why you do not call onSuccess() or onFailure() is because you are not actually calling the method or making the request with AsyncHttpClient , you must necessarily call one of the two .

Even if you do not have an Internet connection this would call the method onFailure()

Ensure you have these import:

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;

import cz.msebera.android.httpclient.Header;
    
answered by 29.05.2018 в 00:57