Reputation: 4427
I am using a MapView with a default location. If I go to another location on the map and then change the orientation of the device, the orientation does not save my previous location. It starts from the default location!
How can I avoid this? I do not want to disable the screen-oreintation change for my application.
Upvotes: 0
Views: 942
Reputation: 6794
Use the method onRetainNonConfigurationInstance()
to save the location and then use getLastNonConfigurationInstance()
in onCreate()
to restore the selected item.
@Override
public Object onRetainNonConfigurationInstance() {
return mapView.getMapCenter();
}
@Override
protected void onCreate(Bundle icicle) {
Geopoint center = (Geopoint) getLastNonConfigurationInstance();
if (point != null)
mapView.getController().animateTo(center);
}
Upvotes: 2