title: AsyncTask: Using web services & threads
body: <p>I am using AsyncTask on button click to refresh the screen. Following is the sequence of events that happen on btn click</p>
  
  <ol>
  <li>progress dialog shows up</li>
  <li>The doInBackground is called and thread is initialized which calls a web service. The web service fetches/uploads data.    A pass/fail flag is set once the web service is called.</li>
  </ol>
  
  <p>My problem is the onPostExecute is never called and therefore the screen is never refreshed.
  And secondly by the time the data is downloaded and the web service sets the flag my code has already hit return stmt in doInBackground.  </p>
  
  <p>Question is how do i stop execution in my asynctask so that the web service is done downloading/uploading the data and finally execute onPostexecute.</p>
  
  <p>FYI
  I also get the following warning in eclipse </p>
  
  <blockquote>
    <p>The method onPostExecute(boolean) from
    the type
    Screen.ConnectWebService is
    never used locally</p>
  </blockquote>
  
  <pre><code>private class ConnectWebService extends AsyncTask &lt;Void, Void, Boolean&gt;
          {
              private final ProgressDialog pd = new ProgressDialog(screen.this);
  
              protected void onPreExecute() {
                  pd.show(Screen.this, "Sync", "Sync in progress",true,false);
              }
  
  
              protected Boolean doInBackground(Void... unused) {
  
                  if (SyncInProgress == false)
                  {
  
                      CallWSThread();//creates thread which  calls web service
                  }
                          Log.d("doInBackground","doInBackground");
                  return SyncStatus;
              }
  
              protected Void onPostExecute(boolean result)
              {   
  
                  pd.dismiss();
                  if (result==true) drawRadioButtons();
  
                   return null;
              }
  
          }
  </code></pre>