It's the first time I use AsyncTask so if the error is very foolish will apologize ...
This is mi class:
class HttpAsyncTask extends AsyncTask<String, Void, String>
{
@Override
protected String doInBackground(String... urls)
{
return null;
}
// onPostExecute displays the results of the AsyncTask.
@Override
protected void onPostExecute(String result)
{
Log.i("ASYNC", "size: "+todo.size());
displayListView();
}
public String POST(String url)
{
InputStream inputStream = null;
String result = "";
try
{
HttpClient httpclient = new DefaultHttpClient();
//make POST request to the given URL
HttpPost httpPost = new HttpPost(url);
// pass parameters in this way
for(int i=0;i<preguntas.length;i++)
{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id",String.valueOf(preguntas[i])));
nameValuePairs.add(new BasicNameValuePair("te",tablas[i]));
//add data
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// 8. Execute POST request to the given URL
HttpResponse httpResponse = httpclient.execute(httpPost);
// 9. receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
// 10. convert inputstream to string
if(inputStream != null)
{
result = convertInputStreamToString(inputStream);
NumPregTem todoAux = new NumPregTem();
todoAux.setBBDD(preguntas[i]) ;
todoAux.setTema(tablas[i]);
String[] aux = result.split(";");
todoAux.setPreg(aux[0]);
todoAux.setRespA(aux[1]);
todoAux.setRespB(aux[2]);
todoAux.setRespC(aux[3]);
todoAux.setRespD(aux[4]);
todoAux.setRespV(aux[5]);
todo.add(todoAux);
}
else
{
result = "Did not work!";
}
}
Log.i("ASYNC", "i've finished to query");
}
catch (Exception e)
{
Log.d("InputStream", e.getLocalizedMessage());
}
return result;
}
}
My problem is that in the debbuger i see the message Log.i("ASYNC", "size: "+todo.size()); in onPostExecute() before the message Log.i("ASYNC", "i've finished to query"); in POST, and the when i use todo.get(i) in my main class (call displayListView() ) this object is null.
thanks you!
i want when the asynchronous task has finished it calls displayListView()
PD: i call POST in this function (in my main class)
HttpAsyncTask httpAsyncTask = new HttpAsyncTask();
httpAsyncTask.execute("http://appdomain.hol.es/webService.php");