First launch of Activity with Google Maps is very slow

前端 未结 9 1792
礼貌的吻别
礼貌的吻别 2020-12-02 12:37

I want to have SupportMapFragment in one of my Activity. I add this fragment directly to layout xml and this layout set as content view. But when Activity is launched for th

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 13:01

    For me it was way slower than 1sec beause i was using:

    mapFragment.getMap();
    

    Then i changed to:

     mapFragment.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                map = googleMap;
            }
     });
    

    Using the getMapAsync() it won't block the ui, so your activity will load before the map. It's still slow, but at least you can show a loading message.

提交回复
热议问题