I am looking to improve the performance of the SupportMapFragment when the device is rotated. It seems as if the fragment must be recreated. I am not sure of this, however when the device is rotated the map tiles must be reloaded. It would make sense from a performance perspective to have the entire mapfragment retained and reused without having to re-instantiate the fragment. Any insight into this would be appreciated.
I am declaring the SupportMapFragment in xml and using the SetupMapIfNeeded() as described in the api docs.
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();
}
}
}
Check out the RetainMapActivity class from the samples. Works like a charm. Here is is:
}