title: Showing a progressDialog from an OptionsMenu
body: <p>I know the following is probably not the best practice and not recommended to do.</p>
  
  <p>I have an AsyncTask that sends data to server. The whole process that i need to do includes 4 web calls using this AsyncTask in quick succession. </p>
  
  <p>I understand that with AsyncTask you must start and stop the ProgressDialog in OnPreExecute and OnPostExecute. I do normally do this.</p>
  
  <p>The problem is that i call 4 AsyncTask in a row one after another, so i don't want 4 Progress dialogs repeating one after another.</p>
  
  <p>I use AsyncTask.execute().get(), so they are called sequentially.</p>
  
  <p>I call these AsyncTasks in a loop from the optionsMenu. What i am trying to do is set up a global ProgressDialog that i can start in the optionsMenu before the loop and cancel it after the loop.</p>
  
  <p>The problem is that it doesn't show. I thought it may be because it needs to run on the UI thread so i placed it inside a Handler, but still no luck.</p>
  
  <p>How can I show the progressdialog from the optionsMenu?</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.menuclientassessment, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
          case R.id.sendclientassessment:
  
              new Handler(Looper.getMainLooper()).post(new Runnable() {
                  @Override
                  public void run() {
  
                      progressDialog2 = new ProgressDialog(ClientAssessmentActivity.this);
                      progressDialog2.setTitle("Connecting to Server");
                      progressDialog2.setMessage("Sending the assessment to server...");
                      progressDialog2.setIndeterminate(true);
  
                      try {
                          progressDialog2.show();
                      } catch(Exception e){
                          //ignore
                      }
                  }
              });
  
              for(int i = 0; i &lt; arr.size(); i++) {
                  String [] params = new String[6];
  
                  AssessmentScore as = null;
                  as = arr.get(i);
  
                  params[0] = clientID;
                  params[1] = carerID;
                  params[2] = comments.getText().toString();
  
                  DateTime now = new DateTime();
                  DateTimeFormatter df = DateTimeFormat.forPattern("yyyy-MM-dd'T'H:mm");
                  String formattedNowTime = df.print(now);
                  params[3] = formattedNowTime;
  
                  params[4] = as.getElementID();
                  params[5] = as.getValue();
  
                  AsyncSendAssessment asa = null;
                  asa = new AsyncSendAssessment();
                  try {
                      asa.execute(params).get();
                  } catch (InterruptedException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (ExecutionException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
  
              }//end of loop
  
              new Handler(Looper.getMainLooper()).post(new Runnable() {
                  @Override
                  public void run() {
                      try {
                          progressDialog2.dismiss();
                          } catch(Exception e) {
                              //ignore
                          }
                  }
              });
  
              return true;
          default:
              return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>