title: AlertDialog created multiple times Android
body: <p>Iam Showing a AlertDialog on Device Shake. The issue is that when I shake the device the AlertDialog shows twice. Hence, if I dismiss the AlertDialog, the top one gets dismissed but there is one still showing after that behind the first one.</p>
  
  <p>Also, Iam showing the same AlertDialog from another section of code where it is shown on a button click which works fine. </p>
  
  <p>All of this is done within a ViewPager.</p>
  
  <p>How can I avoid this scenario?</p>
  
  <p>Here is my code:-</p>
  
  <pre><code>@Override
  public void onShake(float force) 
  {
      // TODO Auto-generated method stub
  
  
      showDialog(timeString, "Confirm .");
  }
  
  public void showDialog(String timeString, String title)
      {
  
          builder = new AlertDialog.Builder(getActivity());
  
          builder.setTitle(title);
          builder.setMessage("Reaching at:"+" "+ timeString+"?");
  
          builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
  
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  // Do nothing
  
              }
          });
  
          builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
  
              public void onClick(DialogInterface dialog, int which) 
              {
                  // Do nothing but close the dialog
  
                  new AddStatusTask().execute();
  
              }
  
          });
  
  
          builder.show();
      }
  </code></pre>