title: Android DialogFragment getActivity() is null
body: <p>I am trying to create a dialog which displays the user a countdown before the user is logged out. The timeout is set from another activity.</p>
  
  <p>I wrote the following code:</p>
  
  <pre><code>import android.app.AlertDialog;
  import android.app.Dialog;
  import android.app.DialogFragment;
  import android.content.DialogInterface;
  import android.content.res.Resources;
  import android.os.Bundle;
  
  public class SessionInactivityDialog extends DialogFragment {
  
      public void setInactivityTimeout(long timeout) {
          Resources res = getActivity().getResources();
          String text = String.format(res.getString(R.string.iminent_logout_text), (timeout / 1000));
          ((AlertDialog)getDialog()).setMessage(text);
      }
  
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  
          builder.setTitle(R.string.iminent_logout);
          builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int id) {
                  SessionActivity activity = (SessionActivity)getActivity();
                  activity.resetTimer();
              }
          });
  
       return builder.create();
      }
  
  }
  </code></pre>
  
  <p>The dialog is called with these lines:</p>
  
  <pre><code>private void showIminentLogoutDialog(long timeout) {
      mInactivityDialog.show(getFragmentManager(), TAG);
      mInactivityDialog.setInactivityTimeout(timeout);
  }
  </code></pre>
  
  <p>Even though the timeout is set after the dialog has opened, <code>getActivity()</code>  in <code>setInactivityTimeout()</code> is <code>null</code>.</p>
  
  <p>How do I get the resources in the fragment correctly?</p>