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");
}
}
我在日志中看到的只是onPreExecute
. 中的代码doInBackground
工作正常,没有例外。我想用当前状态更新文本视图,但为什么不调用所有步骤?
谢谢