title: How to improve fragment loading speed?
body: <p><strong>Performance Enhancement:</strong></p>
  <p>Previously I saved <strong>ALL</strong> images in <code>drawable</code> folder, this might be the reason why the map first loads slow, when draw the markers on screen, the image may not fit the screen size. <strong>Now</strong> I saved images in <code>drawable-mdpi</code>, <code>drawable-hdpi</code> and so on, the app works smoother than before. Hope it helps</p>
  <p><strong>Original Question:</strong></p>
  <p>I created a map in a fragment, the source code can be found below.</p>
  <p>The map fragment is sluggish when <strong>the first time</strong> it loads. If I go any other fragment and click the map fragment again, it loads fast and no slug anymore.</p>
  <p>Can anyone tell me what is going on here? Thanks!</p>
  <p>fragment_map.xml,  id is <code>map</code></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;fragment xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:map=&quot;http://schemas.android.com/apk/res-auto&quot;
      android:id=&quot;@+id/map&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:name=&quot;com.google.android.gms.maps.SupportMapFragment&quot; /&gt;
  </code></pre>
  <p>MyMapFragment.java (contains <code>onCreateView</code> and <code> setUpMapIfNeeded</code>)</p>
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      try {
          rootView = inflater.inflate(R.layout.fragment_map, container, false);
      } catch (InflateException e) {
      /* map is already there, just return view as it is */
          Log.e(TAG, &quot;inflateException&quot;);
      }
  
      setUpMapIfNeeded();
       
      return rootView;
  }
  
  
  public void setUpMapIfNeeded() {
      // Do a null check to confirm that we have not already instantiated the fragment_map.
      if (myMap == null) {
          // Try to obtain the fragment_map from the SupportMapFragment.
          myMap = ((SupportMapFragment) MainActivity.fragmentManager.findFragmentById(R.id.map)).getMap();
          // Check if we were successful in obtaining the fragment_map.
          if (myMap != null) {
              setUpMap();
          }
      }
  }
  </code></pre>