protected void removeDialog(int dialogId) {
   // mDialogFragment may not be visible yet in parent fragment's onResume().
   // To be able to dismiss dialog at that time, don't check
   // mDialogFragment.isVisible().
   if (mDialogFragment != null && mDialogFragment.getDialogId() == dialogId) {
     mDialogFragment.dismiss();
   }
   mDialogFragment = null;
 }
 protected void showDialog(int dialogId) {
   if (mDialogFragment != null) {
     Log.e(TAG, "Old dialog fragment not null!");
   }
   mDialogFragment = new SettingsDialogFragment(this, dialogId);
   mDialogFragment.show(getActivity().getFragmentManager(), Integer.toString(dialogId));
 }
 @Override
 public void onDetach() {
   if (isRemoving()) {
     if (mDialogFragment != null) {
       mDialogFragment.dismiss();
       mDialogFragment = null;
     }
   }
   super.onDetach();
 }
 /**
  * Sets the OnDismissListener of the dialog shown. This method can only be called after
  * showDialog(int) and before removeDialog(int). The method does nothing otherwise.
  */
 protected void setOnDismissListener(DialogInterface.OnDismissListener listener) {
   if (mDialogFragment != null) {
     mDialogFragment.mOnDismissListener = listener;
   }
 }