title: How to Cancel a ProgressDialog without call Dismiss?
body: <p>The cancel's Toast and the dismiss's Toast appears when I press the Cancel Button. How can I solve this?. Thanks.</p>
  
  <p>EDIT : I need a Toast when push the Cancel Button, and I need another different Toast when the ProgressDialog finish correctly (when I dismiss it). But now, I have the correct Toast when ProgressDialog finish correctly, but when I push the Cancel Button the result is both Toast. (It's a ProgressDialog with a bar that is incremented by 5 to complete).Sorry for my english :S</p>
  
  <pre><code>myPd_bar.setOnCancelListener(new OnCancelListener(){
  
                  public void onCancel(DialogInterface dialog) {
                      // TODO Auto-generated method stub
                      Toast.makeText(MainActivity.this,"Cancelled.",
                              Toast.LENGTH_LONG).show();
  
                  }});
  
              myPd_bar.setOnDismissListener(new OnDismissListener() {
  
                  public void onDismiss(DialogInterface arg0) {
                      // TODO Auto-generated method stub
                      Toast.makeText(getApplicationContext(), "Done.",
                              Toast.LENGTH_SHORT).show();
                  }
              });
              myPd_bar.setButton("Cancel", new DialogInterface.OnClickListener() 
              {
                  public void onClick(DialogInterface dialog, int which) 
                  { 
                      myPd_bar.cancel();
                  }
              });
  
              myPd_bar.show();
  </code></pre>
  
  <p><strong>EDIT2 : The final solution :</strong></p>
  
  <pre><code>private int sw = 0;
  
  myPd_bar.setOnDismissListener(new OnDismissListener() {
  
                      public void onDismiss(DialogInterface arg0) {
  
                          if (sw==0){
                          Toast.makeText(getApplicationContext(), "Envio Realizado Correctamente.",
                                  Toast.LENGTH_SHORT).show();
                          }
                          myPd_bar.dismiss();
                              sw=0;
                          }
                  });
  
  
                  //Botón Cancelar.
                  myPd_bar.setButton("Cancelar", new DialogInterface.OnClickListener() 
                  {
                      public void onClick(DialogInterface dialog, int which) 
                      { 
                          sw = 1;
                          //Mostramos el mensaje al cancelar.
                          Toast.makeText(MainActivity.this,"Envío Cancelado.", Toast.LENGTH_LONG).show();
                          myPd_bar.cancel();
                      }
                  });
  
                  myPd_bar.show();
  </code></pre>