First launch of Activity with Google Maps is very slow

前端 未结 9 1790
礼貌的吻别
礼貌的吻别 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条回答
  •  误落风尘
    2020-12-02 12:57

    Similar to the other solutions here, but using RxJava + RxAndroid.

    Just call this snippet from the launcher activity onCreate.

    Observable.fromCallable(new Callable() {
        @Override
        public Void call() {
            MapView mapView = new MapView(LaunchActivity.this); // Replace LaunchActivity with appropriate activity's name
            mapView.onCreate(null);
            return null;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(
        new Action1() {
            @Override
            public void call(Void ignorable) {
                Log.i("Google Maps", "Initialised Google Maps.");
            }
        }, new Action1() {
            @Override
            public void call(Throwable ignorable) {
                Log.w("Google Maps", "[EXPECTED] Initialized Google Maps but got: " + ignorable.getMessage());
            }
        });
    

提交回复
热议问题