public class HttpPostTask extends AsyncTask<Void, Integer, Void> {
TextView txtStatus = (TextView)findViewById(R.id.txtStatus);
@Override
protected Void doInBackground(Void... params) {
EditText editText1 = (EditText)findViewById(R.id.editText1);
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://83.254.xx.xx/android/service.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("action", "savedata"));
nameValuePairs.add(new BasicNameValuePair("data", editText1.getText().toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPreExecute(){
Log.i("debug", "onPreExecute");
}
protected void onProgressUpdate(Integer... progress) {
Log.i("debug", "onProgressUpdate, " + progress[0]);
}
protected void onPostExecute() {
Log.i("debug", "onPostExecute");
}
}
All i see in the log is the onPreExecute. The code in doInBackground works fine, and there are no exceptions. I would like to update a textview with the current status, but why doesnt all steps get called?
Thanks
Two issues:
onPostExcutetakes a parameter that is of the same type as the return value fordoInBackground, so the version you have is not the same method signature (you didn’t actually override the method) and won’t get called. It should beonPostExecute(Void result)onProgressUpdateonly gets called whenever you callpublishProgressfrom your background method. If you don’t call publish, no updates will fire.Just a point of note, if you get in the habit of using the
@Overrideattribute, issues like #1 will be caught by the compiler.HTH