How to load Google map in background in android?

陌路散爱 提交于 2019-12-11 01:38:17

问题


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>

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?


回答1:


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
}


来源:https://stackoverflow.com/questions/28609034/how-to-load-google-map-in-background-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!