Calling Web Service Using Async Task In Android?
I have my separate web service class in which i just pass response method, url and array list of data which is required for making the request and getting the response. I call this
Solution 1:
You can try below code for Async Task and also call web service in doInBackground:
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
publicclassAsyncExampleextendsActivity{
privateString url="http://www.google.co.in";
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
newAsyncCaller().execute();
}
privateclassAsyncCallerextendsAsyncTask<Void, Void, Void>
{
ProgressDialog pdLoading = newProgressDialog(AsyncExample.this);
@OverrideprotectedvoidonPreExecute() {
super.onPreExecute();
//this method will be running on UI thread
pdLoading.setMessage("Loading...");
pdLoading.show();
}
@OverrideprotectedVoiddoInBackground(Void... params) {
//this method will be running on a background thread so don't update UI from here//do your long-running http tasks here, you don't want to pass argument and u can access the parent class' variable url over herereturnnull;
}
@OverrideprotectedvoidonPostExecute(Void result) {
super.onPostExecute(result);
//this method will be running on UI thread
pdLoading.dismiss();
}
}
}
Done
Post a Comment for "Calling Web Service Using Async Task In Android?"