code: public void rewriteHistory(Activity activity, HistoryRewriter historyRewriter) {
      checkOnCreateNotYetCalled(activity, "rewriteHistory() must be called before onCreate()");
      historyRewriter.rewriteHistory(backStack);
    }
docs: Change the elements of the back stack according to the implementation of the HistoryRewriter parameter.
  <b>Note, this method cannot be called after calling {@link #onCreate(Activity, Bundle)} on this Navigator.</b> The
  primary use case for this method is to change the back stack before the navigator is fully initialized (e.g.
  showing a login screen if necessary). It is possible to manipulate the back stack with a {@link HistoryRewriter},
  {@link #navigate(HistoryRewriter)}.
  
  @param activity  activity used to verify this Navigator is in an acceptable state when resetWithRoot is called
  @param historyRewriter  rewrites back stack to desired state
  @throws IllegalStateException if {@link #onCreate(Activity, Bundle)} has already been called on this Navigator