我希望在旋转设备时提高SupportMapFragment的性能.似乎必须重新创建片段.我不确定这一点,但是当旋转设备时,必须重新加载地图图块.从性能角度来看,保留并重用整个mapfragment而不必重新实例化片段是有意义的.任何洞察这一点将不胜感激.
我在xml中声明了SupportMapFragment,并使用api docs中描述的SetupMapIfNeeded().
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
// map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
Run Code Online (Sandbox Code Playgroud)