How to improve fragment loading speed?

后端 未结 5 765
清歌不尽
清歌不尽 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:07

    I'm using a very hackish but effective way in my application, but it works good. My mapFragment is not displayed right after the app launches! Otherwise this would not make sense.

    Put this in your launcher activity's onCreate:

        // Fixing Later Map loading Delay
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    MapView mv = new MapView(getApplicationContext());
                    mv.onCreate(null);
                    mv.onPause();
                    mv.onDestroy();
                }catch (Exception ignored){
    
                }
            }
        }).start();
    

    This will create a mapview in an background thread (far away from the ui) and with it, initializes all the google play services and map data.

    The loaded data is about 5MB extra.

    If someone has some ideas for improvements feel free to comment please !


    Java 8 Version:

    // Fixing Later Map loading Delay
    new Thread(() -> {
        try {
            MapView mv = new MapView(getApplicationContext());
            mv.onCreate(null);
            mv.onPause();
            mv.onDestroy();
        }catch (Exception ignored){}
    }).start();
    

提交回复
热议问题