0

I have this AsyncTask

public class clientesAsyncTask extends AsyncTask<Void, Void,String> {
private String user,password,response;
private String clientesUrl="example.org/services/data.php";
private int distance;

ArrayList<Cliente> listaClientes;
public clientesAsyncTask(String user,String password) {
    this.user=user;
    this.password=password;
    response="";

}

@Override
protected void onPreExecute() {
    // TODO Auto-generated method stub
    super.onPreExecute();
}

@Override
protected String doInBackground(Void... params) {


    try {
        URL url = new URL(clientesUrl);
        HttpURLConnection hConnection = (HttpURLConnection)url.openConnection();
        HttpURLConnection.setFollowRedirects(true);
        hConnection.setReadTimeout(10000);
        hConnection.setConnectTimeout(15000);
        hConnection.setDoOutput(true);
        hConnection.setDoInput(true);
        hConnection.setRequestMethod("POST");

        Uri.Builder builder = new Uri.Builder()
                .appendQueryParameter("usuario", user)
                .appendQueryParameter("password", password);
        String query = builder.build().getEncodedQuery();

        OutputStream os = hConnection.getOutputStream();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
        writer.write(query);
        writer.flush();
        writer.close();
        os.close();

        hConnection.connect();

        int responseCode=hConnection.getResponseCode();

        if (responseCode == HttpsURLConnection.HTTP_OK) {
            String line;

            BufferedReader br=new BufferedReader(new InputStreamReader(hConnection.getInputStream()));
            while ((line = br.readLine()) != null) {

                response+=line;
            }
            hConnection.disconnect();
        }
        else {
            response="";
            throw new Exception(responseCode+"");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    Log.d("Response", response);

    return response;

}

@Override
protected void onPostExecute(String response) {
    super.onPostExecute(response);

}

}

I call it after another AsyncTask

loginTask=new loginAsyncTask(user,password);
String autenticacion=loginTask.execute((Void)null).get();

clientesAsyncTask clientesTask= new clientesAsyncTask(user,pass);
String data =clientesTask.execute((Void)null).get();

But in "resposne" is returning messages from the adb logger,is not returning the response from the request. I use exactly the same asynctask whith a diferent name to perform both AsyncTask but the second is only returning adb log messages, why? I tested the request on my browser and it has no errors. What is causing this?

EDIT 1 My AsyncTask is not related to other. I have made the Test Files for each task and the problem continues.

UrielUVD
  • 482
  • 1
  • 9
  • 27
  • possible duplicate of [Android calling AsyncTask right after an another finished](http://stackoverflow.com/questions/10048958/android-calling-asynctask-right-after-an-another-finished) – Josh Fischer Sep 14 '15 at 03:31
  • I deleted the another AsycTask and just the last one is running, and is still showing adb messages as the response of the request. So is not a problem of multiple AsyncTask – UrielUVD Sep 14 '15 at 03:36

0 Answers0