title: How to identify if a view contains a dialog in android?
body: <p>I am displaying dialog box in android.Also these dialog object are not global but their scope is within the method were it is used.When i come from background to foreground i need to identify whether the dialog is displayed if yes dismiss it.I want to know how to identify if a view is displaying a dialog if yes then dismiss the dialog.
  Following is my code:</p>
  
  <pre><code>public void reentersecuredpin()
      {
           final Dialog dialog = new Dialog(MainActivity.this,android.R.style.Theme_Translucent_NoTitleBar);
           dialog.setContentView(R.layout.successful_securepin_creation);
           dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
            dialog.setCancelable(true);
  
        Button btn_Ok;
  
        btn_Ok=(Button)dialog.findViewById(R.id.btn_Ok_successful_created_pin);
       TextView text1_success,text2_success;
       text1_success=(TextView)dialog.findViewById(R.id.text1_success);
       text2_success=(TextView)dialog.findViewById(R.id.text2_success);
  
  
       text1_success.setText("You have entered wrong Pin");
       text2_success.setText("Please re-enter your password again");
  
  
        btn_Ok.setOnClickListener(new View.OnClickListener() 
       {
  
                  @Override
                  public void onClick(View v) 
                  {
                      dialog.cancel();
  
                  }
              });
  
           dialog.show();
  
      }
  </code></pre>
  
  <p>So when i come from background to foreground:</p>
  
  <pre><code>  @Override
      protected void onResume() 
      {
  
          super.onResume();
          background_to_foreground_dialog();
  
      }
  </code></pre>
  
  <p>The background_to_foreground_dialog() displays another dialog.The problem what i am facing here is background_to_foreground_dialog() draws dialog on another dialog (when user had gone to background).How can i dismiss the previous dialog before drawing  background_to_foreground_dialog().</p>