title: DialogFragment on Fragment with screen rotation
body: <p>On my main activity I have a Fragment in which I apply setRetainInstance(true) so that the AsyncTask I use into it is not disturbed by orientation change.</p>
  
  <p>A lot of work is processed by the AsyncTask. That's why I would like to display a dialog with a progressBar on top of my activity.</p>
  
  <p>I made some researches and I succeed in doing with a DialogFragment:</p>
  
  <p>public class DialogWait extends DialogFragment {</p>
  
  <pre><code>private ProgressBar progressBar;
  
  public DialogWait() {
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.dialog_wait, container);
  
      Dialog dialog = getDialog();
      dialog.setTitle("Hello");
      setCancelable(false);
  
      progressBar = (ProgressBar) view.findViewById(R.id.progress);
  
      return view;
  }
  
  public void updateProgress(int value) {
      progressBar.setProgress(value);
  }
  </code></pre>
  
  <p>And here is my AsyncTask:</p>
  
  <pre><code>public class InitAsyncTask extends AsyncTask&lt;Void, Integer, Void&gt; {
  
  private Context activity;
  private OnTaskDoneListener mCallback;
  private DialogWait dialog;
  
  public InitAsyncTask(Context context, OnTaskDoneListener callback, DialogWait dialogWait) {
      activity = context;
      mCallback = callback;
      dialog = dialogWait;
  }
  
  @Override
  protected Void doInBackground(Void... params) {
      doStuff();
  
      return null;
  }
  
  @Override
  protected void onProgressUpdate(Integer... values) {
      dialog.updateProgress(values[0]);
  }
  
  @Override
  protected void onPostExecute(Void result) {     
      publishProgress(100);
              if(dialog != null)
           dialog.dismiss();
      mCallback.onTaskDone();
  }
  
  private void doStuff() {
            //...
      }
  </code></pre>
  
  <p>}</p>
  
  <p>If I don't change the screen rotation, it works fine. But if I do, the dialog is dismissed and a few seconds later, I got a NullPointerEsception which nonsense since I set the condition: if(dialog != null)</p>
  
  <p>What am I doing wrong?</p>