How to improve fragment loading speed?

后端 未结 5 769
清歌不尽
清歌不尽 2020-12-04 14:38

Performance Enhancement:

Previously I saved ALL images in drawable folder, this might be the reason why the map first l

5条回答
  •  清歌不尽
    2020-12-04 15:20

    Just to add to @Xyaren's answer, I needed it to work for SupportFragment which seemed to require some extra steps. Have your activity implement OnMapReadyCallback.

    In your onCreate:

    new Thread(() -> {
        try {
            SupportMapFragment mf = SupportMapFragment.newInstance();
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.dummy_map_view, mf)
                    .commit();
            runOnUiThread(() -> mf.getMapAsync(SplashActivity.this));
        }catch (Exception ignored){
            Timber.w("Dummy map load exception: %s", ignored);
        }
    }).start();
    

    You'll have to implement this:

    @Override
    public void onMapReady(GoogleMap googleMap) {
        // Do nothing because we only want to pre-load map.
        Timber.d("Map loaded: %s", googleMap);
    }
    

    and in your activity layout:

    
    

    It needs to go through all the steps including the transaction for Google Play Services to download the map data.

提交回复
热议问题