title: Dismiss DialogFragment that's instanciated in a Base Activity class
body: <p>My application checks in MainActivity eclusively if Gps is enabled. If not a DialogFragment appears which guides the user to Android Location Settings. </p>
  
  <p>On accessing all Activities a Dialog appears if no network/internet-connection is established or even connecting to a network. </p>
  
  <p>Since this check is necessary in all Activities I've implemented a BaseActivity for all my Activities and implemented the check in onStart(). </p>
  
  <p>When the user returns from managing the Location Settings, a second EnableInternetDialogFragment appears. The first (not solved) dialog is still visible</p>
  
  <p>My current solution is to dismiss the dialog in the onPause() method, but this doesn't work well at all. </p>
  
  <p>Is there a way to avoid/manage this behaviour?</p>
  
  <pre><code>public abstract class BaseActivity extends FragmentActivity {
  
      protected ConnectivityTester connectivityTester;
      protected ConnectivityHelper connectivityHelper;
  
      protected EnableInternetDialogFragment enableInternetDialogFragment;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          connectivityTester = new ConnectivityTester();
          connectivityHelper = new ConnectivityHelper();
      }
  
      @Override
      protected void onStart() {
          super.onStart();
          final boolean internetEnabled = connectivityTester.isInternetEnabled(getApplicationContext());
          if (!internetEnabled) {
              enableInternetDialogFragment = new EnableInternetDialogFragment();
              enableInternetDialogFragment.show(getSupportFragmentManager(), "enableInternetDialog");
          }
      }
  
      @Override
      protected void onPause() {
          super.onPause();
          if (enableInternetDialogFragment.getDialog() != null) {
              enableInternetDialogFragment.dismissAllowingStateLoss();
          }
      }
  
  
      public final class EnableInternetDialogFragment extends DialogFragment {
  
          @Override
          public Dialog onCreateDialog(Bundle savedInstanceState) {
              return new AlertDialog.Builder(getActivity())
                  .setTitle("Activite Network/Internet")
                  .setMessage("test")
                  .setPositiveButton("Activate Internet", new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          connectivityHelper.enableMobileInternetSettings(getApplicationContext());
                      }
                  })
                  .setNegativeButton("Activate WiFi", new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          connectivityHelper.enableWiFiSettings(getApplicationContext());
                      }
                  }).create();
          }
      }
  </code></pre>
  
  <p>}</p>