title: Google map fragment in another fragment
body: <p>I have a Fragment that gets displayed in a tab layout.</p>
  
  <pre><code>public class MyFragment extends Fragment {
  
      private GoogleMap map;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_map, container, false);
          map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
          ...
  </code></pre>
  
  <p>However I run into problems when onCreateView gets called again, the inflate method fails because there is already a MapFragment.</p>
  
  <p>I am not sure what the right answer is here as I feel like this is a bug in android.  I.E. I did not create the SupportMapFragment programmatically so I don't feel like I should have to destroy it programatically.</p>
  
  <p>I have seen 'solutions' that say you need to destroy it:</p>
  
  <pre><code>public void onDestroy() {
         try {
              Fragment fragment = (getFragmentManager().findFragmentById(R.id.map_fragment));  
              FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
              ft.remove(fragment);
              ft.commit();
          } catch (Exception e) {
              e.printStackTrace();
          }
  }
  </code></pre>
  
  <p>However if I do that I get:</p>
  
  <pre><code>&gt; 04-07 13:59:00.801: W/System.err(20067):
  &gt; java.lang.IllegalStateException: Can not perform this action after
  &gt; onSaveInstanceState 04-07 13:59:00.801: W/System.err(20067):  at
  &gt; android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1343)
  &gt; 04-07 13:59:00.801: W/System.err(20067):  at
  &gt; android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1361)
  &gt; 04-07 13:59:00.801: W/System.err(20067):  at
  &gt; android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
  </code></pre>
  
  <p>Here is my fragment XML:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:map="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;fragment
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.SupportMapFragment"
          map:uiCompass="false"
          map:uiRotateGestures="false"
          map:uiTiltGestures="false"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>If Android inflated the SupportMapFragment should it not destroy that fragment as well.  If not how am I supposed to destroy the SupportMapFragment 'correctly' such that another call to onCreateView does not fail, but also such that I do not get an exception in onDestroyView().</p>