如何在Android的后台加载Google Map? [英] How to load Google map in background in android?

查看:193
本文介绍了如何在Android的后台加载Google Map?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XML文件中有地图的片段,如下所示,

I have fragment for map in XML file as below,

<fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" >
    </fragment>

我要在哪个活动中显示Google地图,这不是主要活动.单击按钮后,我将从主活动重定向到地图活动.地图没有任何问题.但是,当我单击主要活动的按钮时,该过程会停止一段时间,突然黑屏出现在前面,然后一段时间,地图活动会显示该地图.这不是应用程序的预期行为.加载地图活动后,有什么方法可以加载该地图吗?我是说要在后台加载地图?

In which activity I am displaying the Google map, that is not a main activity. I am redirecting to map activity from my main activity on button click. There is no any problem with map. But when I click on button of main activity then the process stops for sometime and suddenly black screen arrives in front and after sometime, map activity displays the map. It is not expected behaviour of application. Is there any way to load that map after map activity loaded? I mean loading map in background?

推荐答案

使用getMapAsync()(在Google Play服务v6.5.87中引入)代替getMap(),然后在您的片段上实现OnMapReadyCallback:

Use getMapAsync() (introduced in Google Play Services v6.5.87) instead of getMap() then Implement OnMapReadyCallback on your fragment:

@Override
public void onMapReady(GoogleMap map) {
    // do something with map
}

这篇关于如何在Android的后台加载Google Map?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆