title: How to implement google map in fragment
body: <p>I have a MainActivity which has an ActionBar with two tab, the first tab is to show the sensor data value and the second tab I want to show the Map.
  But I have a problem to implement the map in the fragment on the second tab</p>
  
  <p>The MainActivity is shown as below:</p>
  
  <pre><code>public class MainActivity extends Activity
  {
  private static final String DATA_FRAGMENT_BAR = "Data";
  private static final String MAP_FRAGMENT_BAR = "Map";
  
  private DataCollection mDataCollection;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Config.mContext = this;
      ActionBar actionBar = getActionBar();
      actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME| ActionBar.DISPLAY_SHOW_CUSTOM);
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
      ActionBar.Tab dataTab = actionBar.newTab().setText(DATA_FRAGMENT_BAR);
      ActionBar.Tab mapTab = actionBar.newTab().setText(MAP_FRAGMENT_BAR);
      Fragment dataFragment = new FragmentData();
      Fragment mapFragment = new FragmentMap();
  
      dataTab.setTabListener(new MyTabsListener(dataFragment));
      mapTab.setTabListener(new MyTabsListener(mapFragment));
  
      actionBar.addTab(dataTab);
      actionBar.addTab(mapTab);
      mDataCollection = DataCollection.getInstance();
  }
  ....
  }
  </code></pre>
  
  <p>The TabsListener is shown as below
      public class MyTabsListener implements ActionBar.TabListener
      {
      private Fragment fragment;</p>
  
  <pre><code>public MyTabsListener(Fragment fragment)
  {
      this.fragment = fragment;
  }
  
  @Override
  public void onTabReselected(Tab tab, FragmentTransaction ft) {
      // TODO Auto-generated method stub
  }
  
  @Override
  public void onTabSelected(Tab tab, FragmentTransaction ft) {
      // TODO Auto-generated method stub
      ft.replace(R.id.fragment_container, fragment);
  }
  
  @Override
  public void onTabUnselected(Tab tab, FragmentTransaction ft) {
      // TODO Auto-generated method stub
      ft.remove(fragment);
  }
  }
  </code></pre>
  
  <p>The the map fragment class is shown as below:</p>
  
  <pre><code>public class FragmentMap extends Fragment
  {
  
  MapView mapView;
  GoogleMap map;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
  {
      View v = inflater.inflate(R.layout.fragment_map, container, false);
      // Gets the MapView from the XML layout and creates it
      mapView = (MapView) v.findViewById(R.id.mapView);
      mapView.onCreate(savedInstanceState);
  
      // Gets to GoogleMap from the MapView and does initialization stuff
      map = mapView.getMap();
      //map.getUiSettings().setMyLocationButtonEnabled(false);
      //map.setMyLocationEnabled(true);
      map.addMarker(new MarkerOptions().position(new LatLng(50.167003,19.383262)));
  
  
      // Needs to call MapsInitializer before doing any CameraUpdateFactory calls
      try 
      {
          MapsInitializer.initialize(this.getActivity());
      } 
      catch (GooglePlayServicesNotAvailableException e)
      {
          e.printStackTrace();
      }
  
      // Updates the location and zoom of the MapView
      CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
      map.animateCamera(cameraUpdate);
  
      return v;
  }
  
  @Override
  public void onResume() 
  {
      mapView.onResume();
      super.onResume();
  }
  
  @Override
  public void onDestroy() 
  {
      super.onDestroy();
      mapView.onDestroy();
  }
  
  @Override
  public void onLowMemory()
  {
      super.onLowMemory();
      mapView.onLowMemory();
  }
  }
  </code></pre>
  
  <p>I set a break point in the FragmentMap class at the line "mapView.onCreate(savedInstanceState);" the savedInstanceState is null and the program will crash after line.</p>
  
  <p>Can someone help. Thanks in advance.</p>