First launch of Activity with Google Maps is very slow

The reason why the first load takes so long is because the Play Services APIs have to load as seen in log lines:

I/Google Maps Android API﹕ Google Play services client version: 6587000
I/Google Maps Android API﹕ Google Play services package version: 6768430

Unfortunately, the "package" one takes about a second to load and using the MapsInitializer only will get you the "client." So here is a a not so pretty work around: Initialize a dummy map in your main launcher activity.

mDummyMapInitializer.getMapAsync(new OnMapReadyCallback() {
  @Override
  public void onMapReady(GoogleMap googleMap) {
    Log.d(TAG, "onMapReady");
  }
});

Now when you load your actual map later on, it shouldn't have to initialize the Play services APIs. This shouldn't cause any delays in your main activity either because the async method executes off the main thread.

Since you have to do the initialization somewhere no matter what, I think it makes sense to do it right when the app starts, so that when you load an activity that actually needs a map, you do not have to wait at all.

Note: mDummyMapInitializer must be a MapFragment or SupportMapFragmentand must be added to the activity, or else the Play Services APIs won't be loaded. The getMapAsync method itself must also be called from the main thread.


Ok so I just had the same issue and think, after viewing this question, that there is no 'nice' solution.

My current hack is to delay adding the fragment, giving the Activity a chance to render everything else before adding the map.

Now, I am embedding the map as a childfragment, so my code looks like this:

    // inside onCreateView
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            if (isAdded()) {
                FragmentManager fm = getChildFragmentManager();
                GoogleMapFragment mapFragment = GoogleMapFragment
                        .newInstance();
                fm.beginTransaction()
                        .replace(R.id.mapContainer, mapFragment).commit();
            }
        }
    }, 1000);

if adding directly to Activity it might look like this:

    // inside onCreate
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            if (!isFinishing()) {
                FragmentManager fm = getFragmentManager();
                GoogleMapFragment mapFragment = GoogleMapFragment
                        .newInstance();
                fm.beginTransaction()
                        .replace(R.id.mapContainer, mapFragment).commit();
            }
        }
    }, 1000);

Nevertheless, a check inside the Runnable is needed to ensure that we are not trying to add the map to some non-existing Activity or Fragment.

I am not a fan of hardcoded delays like this, so will return if I come up with something better. 1 second should be plenty though and could probably be even less.


I solved it by using MapsInitializer in my Application.onCreate():

MapsInitializer.initialize(this);

Good results and cleaner (and not hacky) solution!


I've been fighting this issue too, and have found considerable improvements by doing the following:

1) Unplug your USB cable (or otherwise disconnect your debugging session) and try it again. Google Maps in an app is much slower when a debugging session is active. Disconnect the debugger and it gets a lot faster... it's still certainly not the fastest, but it's at least acceptable.

2) Don't call setMapType() unless you've already called getMapType() and confirmed that it's different from what you want to set it to. Multiple calls for the same Map Type will still cause it to reset each time, which can take time.

3) Add the Map fragment programmatically, similar to what @cYrixmorten posted, but I do it from a background thread started at the end of my onResume(), which then waits 50ms and then runs it on the UI thread. This keeps it from hitting the UI thread right away, so that gives the Activity time to load and display; you should at least be on screen while the map is possibly choking everything up.

The catch here is that you want to create a new MapFragment instance only once per Activity, not every time the screen orientation is rotated. What I do is call "getFragmentManager().findFragmentById(R.id.mapContainer)", which will either give me the map fragment handle from last time, or a null if this is the first time (in which case I'll create the map fragment and do the FragmentManager.replace() ).