Estoy tratando de crear una conexión HTTP usando la clase AsyncTask.Cómo crear una conexión Http usando la clase AsyncTask?
¿Es posible crear una conexión HTTP?
¿Puede sugerir el código fuente de la muestra?
Gracias de antemano.
Estoy tratando de crear una conexión HTTP usando la clase AsyncTask.Cómo crear una conexión Http usando la clase AsyncTask?
¿Es posible crear una conexión HTTP?
¿Puede sugerir el código fuente de la muestra?
Gracias de antemano.
Como una clase interna dentro de su actividad:
public final class HttpTask
extends
AsyncTask<String/* Param */, Boolean /* Progress */, String /* Result */> {
private HttpClient mHc = new DefaultHttpClient();
@Override
protected String doInBackground(String... params) {
publishProgress(true);
// Do the usual httpclient thing to get the result
return result;
}
@Override
protected void onProgressUpdate(Boolean... progress) {
// line below coupled with
// getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS)
// before setContentView
// will show the wait animation on the top-right corner
MyActivity.this.setProgressBarIndeterminateVisibility(progress[0]);
}
@Override
protected void onPostExecute(String result) {
publishProgress(false);
// Do something with result in your activity
}
}
Entonces en algún lugar de su actividad:
new HttpTask().execute(someParams...);
Creo que esto puede ayudar u ...
http://androidbeginner.blogspot.com/2010/01/communication-with-httprequest.html
Atul yadav