Code example for SupportMapFragment

Methods: getMap, onResume

0
            setUpMapIfNeeded(); 
        } 
 
        @Override 
        public void onResume() { 
            super.onResume(); 
            setUpMapIfNeeded(); 
        } 
 
        @Override 
        public void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
 
            // All Parcelable objects of the API  (eg. LatLng, MarkerOptions, etc.) can be set 
            // directly in the given Bundle. 
            outState.putParcelable(MARKER_POSITION, mMarkerPosition);
 
            // All other custom Parcelable objects must be wrapped in another Bundle. Indeed, 
            // failing to do so would throw a ClassNotFoundException. This is due to the fact that 
            // this Bundle is being parceled (losing its ClassLoader at this time) and unparceled 
            // later in a different ClassLoader. 
            Bundle bundle = new Bundle();
            bundle.putParcelable(MARKER_INFO, mMarkerInfo);
            outState.putBundle(OTHER_OPTIONS, bundle);
        } 
 
        @Override 
        public boolean onMarkerClick(Marker marker) {
            float newHue = MARKER_HUES[new Random().nextInt(MARKER_HUES.length)];
            mMarkerInfo.mHue = newHue;
            marker.setIcon(BitmapDescriptorFactory.defaultMarker(newHue));
            return true; 
        } 
 
        private void setUpMapIfNeeded() { 
            // Do a null check to confirm that we have not already instantiated the map. 
            if (mMap == null) {
                // Try to obtain the map from the SupportMapFragment. 
                mMap = getMap();
                // Check if we were successful in obtaining the map. 
                if (mMap != null) {
                    setUpMap(); 
                } 
            }