hi all,
I am developing an application which require accessing a website for data, and will show that data on device. I wants to fetch data from Internet in background and show ProgressDialog or ProgressBar on device and when application receive response from server app will dismiss the dialog or bar and will show data .
For this i am using AsyncTask -
code for AsyncTask is as follows--
ServerTask extends AsyncTask { @Override protected void onPreExecute() { dialogAccessingServer = new ProgressDialog(ctx); dialogAccessingServer.setMessage(shownOnProgressDialog); dialogAccessingSpurstone.show(); }
@Override
protected ServerResponse doInBackground(String... urlArray) {
String urlString = urlArray[0];
HttpResponse serverResponseObject = null;
//finding HttpResponse
return serverResponseObject;
}//end of doInBackground
@Override
protected void onPostExecute(HttpResponse serverResponseObject){
dialogAccessingSpurstone.dismiss();
}
}
and calling this code as follows--
ServerTask serverTaskObject = new ServerTask(); serverTaskObject.execute(); HttpResponse response = serverTaskObject.get();
//performing operation on response
but ProgressDialog is not shown.(I guess the reason for it is the thread is not complete and android invalidate only when thread has completed).
My Questions -- 1- If my guess is right ? If yes then how I should implement it? 2- If there is any other better way to do this?
thanks