title: Fragment without a view crashes on configuration change
body: <p>I have an UI where I need a <code>Fragment</code> to be displayed (with a view) in landscape mode but not in portrait mode. In portrait mode it should still be available but will display its result using <code>ListPopupWindow</code> instead.</p>
  
  <p>I figured I could handle this by using the <code>&lt;fragment /&gt;</code> tag for the landscape layout while creating the fragment programmatically if it wasn't started (in the case when we are in portrait).</p>
  
  <p>This works fine as long as you start out in landscape, if you start in portrait where the fragment is created programmatically your application will crash when you rotate the emulator when it tries to attach the fragment to your layout:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException:
    Fragment  did not create a view.
    at
    android.app.Activity.onCreateView(Activity.java:4095)</p>
  </blockquote>
  
  <p>The docs for <code>Fragment.isInLayout()</code> seems to hint that it should be able to handle it this way:</p>
  
  <blockquote>
    <p>Return true if the layout is included
    as part of an activity view hierarchy
    via the  tag. This will
    always be true when fragments are
    created through the  tag,
    except in the case where an old
    fragment is restored from a previous
    state and it does not appear in the
    layout of the current state.</p>
  </blockquote>
  
  <p>So the question is how to do this correctly or if there is something I'm missing?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Seems like <code>isInLayout()</code> isn't behaving as it should currently as well. It returns false if you have added a <code>Fragment</code> to a container manually. </p>
  
  <p>Also, if you add a <code>Fragment</code> manually to a container and then rotate (the device) to a layout that does not contain that layout it will crash:</p>
  
  <blockquote>
    <p>Caused by:
    java.lang.IllegalArgumentException: No
    view found for id 0x7f060011 for
    fragment SearchFragment{4042f868 #2
    id=0x7f060011 SearchFragment} at
    android.app.FragmentManagerImpl.moveToState(FragmentManager.java:722)</p>
  </blockquote>