我在自己的片段(android.support.v4.app.FFragment(中使用com.google.android.gms.maps.MapView,如下所示:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.fragments.MapsFragment">
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map_view" />
</FrameLayout>
我有一个问题,只有在第一次运行时,当我在设备上运行应用程序时,回调onMapReady才会被调用两次。当我停止应用程序并再次运行时,这种情况不会再次发生。代码:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_maps, container, false);
mMapView = (MapView) v.findViewById(R.id.map_view);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(this);
[...]
return v;
}
此外,我调用映射视图的这些回调:onResume、onPause、onDestroy、onLowMemory。我在其他任何地方都不使用mMapView变量。
有什么想法吗?我在MapView实现中是否做错了什么?
谢谢!
删除此行:
mMapView.getMapAsync(this);
如果您像View
一样使用它,它将被自动调用。