Fetching data from Internet in background and showing ProgressDialog or ProgressBar
<p>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 .</p>

<p>For this i am using AsyncTask -</p>

<p>code for AsyncTask is as follows--</p>

<pre><code>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();

        }

}
</code></pre>

<p>and calling this code as follows--</p>

<pre><code>ServerTask serverTaskObject = new ServerTask();
serverTaskObject.execute();
HttpResponse response = serverTaskObject.get();
</code></pre>

<p>//performing operation on response</p>

<p>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).</p>

<p>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?</p>

<p>thanks </p>
