title: Map Fragment couldn't be modified after Fragment Reload
body: <ol>
  <li><p>I have an <strong>activity</strong> with <em>Navigation Drawer</em> and <strong>HomeFragment</strong>.</p></li>
  <li><p><strong>HomeFragment</strong> contains two nested fragments (child fragments): <em>SupportMapFragment</em> and <strong>ActionFragment</strong>.</p></li>
  </ol>
  
  <p>I declare the GoogleMap object <em><code>sMap</code></em> as static in <strong>HomeFragment</strong>, so it can be accessed and modified by the nested fragment <strong>ActionFragment</strong>.</p>
  
  <p>Everything works fine in the first run. The map can be manipulated from within the <strong>ActionFragment</strong>. But when the HomeFragment is removed and reloaded at a later point of time, the map could only be modified from the HomeFragment (parent fragment) and not from the ActionFragment (nested fragment) anymore.</p>
  
  <p>I am failing to understand why something that works in the first instance doesn't work when the fragment is reloaded. Below are the codes which I have kept to minimum for easier understanding.</p>
  
  <hr>
  
  <p><strong>HomeFragment.java</strong> (Parent fragment)</p>
  
  <pre><code>public class HomeFragment extends Fragment {
  
      private static GoogleMap sMap;
      public static GoogleMap getMap() {
          return sMap;
      }
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate layout
          return inflater.inflate(R.layout.f_home, container, false);
      }
  
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState){
          super.onActivityCreated(savedInstanceState);
  
          // Obtain the GoogleMap object
          try {
              if (sMap == null) {
                  sMap = ((SupportMapFragment) getActivity().getSupportFragmentManager()
                          .findFragmentById(R.id.home_map)).getMap();
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          // Load child fragment
          if (savedInstanceState == null) {
              Fragment _actionFragment = new ActionFragment();
              FragmentTransaction _ft = getChildFragmentManager().beginTransaction();
              _ft.replace(R.id.action_container_bottom, _actionFragment);
              _ft.commit();
          }
      }
  
  
      @Override
      public void onDestroyView(){
          super.onDestroyView();
  
          // Remove the map fragment to prevent errors on the next load
          if(sMap != null){
              try {
                  getActivity().getSupportFragmentManager()
                              .beginTransaction()
                              .remove(getActivity().getSupportFragmentManager()
                                      .findFragmentById(R.id.home_map))
                              .commit();
  
                  sMap = null;
              } catch (Exception e){}
          }
      }
  }
  </code></pre>
  
  <p><strong>f_home.xml</strong> (Layout of parent fragment)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;fragment
          android:id="@+id/home_map"
          android:name="com.google.android.gms.maps.SupportMapFragment"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
      &lt;FrameLayout
          android:id="@+id/action_container_bottom"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>ActionFragment.java</strong> (Nested or Child fragment)</p>
  
  <pre><code>public class ActionFragment extends Fragment {
      private static GoogleMap sMap = HomeFragment.getMap();
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          return inflater.inflate(R.layout.f_action, container, false);
      }
  
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState){
          super.onActivityCreated(savedInstanceState);
  
          // check if map is created successfully or not
          if (sMap != null) {
              sMap.clear();
              sMap.setPadding(0, 0, 0, 300);
              sMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
              sMap.setBuildingsEnabled(false);
              sMap.setMyLocationEnabled(false);
              sMap.getUiSettings().setRotateGesturesEnabled(false);
              sMap.getUiSettings().setTiltGesturesEnabled(false);
              sMap.getUiSettings().setZoomControlsEnabled(false);
              sMap.moveCamera(CameraUpdateFactory.zoomTo(12));
          }
      }
  }
  </code></pre>
  
  <p>Any help would be immensely appreciated as I am struggling with this for a long time. Thank you!</p>