title: Xamarin Android - Dismiss DialogFragment
body: <p>I have looked on several different threads on how to dismiss a DialogFragment but nothing seems to work for me. I want to be able to close the DialogFragment when I switch to a new Activity from the click event that I have. I tried by using something like <code>this.Activity.Dismiss()</code> from the click event but also tried this from where I show the DialogFragment: </p>
  
  <pre><code>if (_exportFragment != null)
              {
                  _exportFragment.Dismiss();
              }
  </code></pre>
  
  <p>But none of these seem to work. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is where I display the DialogFragment:</p>
  
  <pre><code>gridview.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs args)
              {
                  // DIALOG FRAGMENT
                  FragmentTransaction ft = FragmentManager.BeginTransaction();
                  //Remove fragment else it will crash as it is already added to backstack
                  Fragment prev = FragmentManager.FindFragmentByTag("dialog");
                  if (prev != null)
                  {
                      ft.Remove(prev);
                  }
  
                  ft.AddToBackStack(null);
  
                  // Create and show the dialog.
                  _exportFragment = new VideoExportDialogFragment();
                  _exportFragment.VideoCreationDate = VideoList[args.Position].CreationDate;
                  //_exportFragment.
                  _exportFragment.VideoPathFragment = VideoListPosition(args.Position);
  
                  //_exportFragment.ThumbnailActivity = this;
                  //Add fragment
                  _exportFragment.Show(ft, "dialog");
                  dismissLoader();
              };
          }
  
          private void dismissLoader()
          {
              if (_exportFragment != null)
              {
                  _exportFragment.Dismiss();
              }
          }
  </code></pre>