Running slightly modified example of Google Maps throws BadParcelableException in the Google Maps code. The LatLng class is parcelable but it canno
I tried the two previous answers without success, but I found another workaround :
When saving the state, be careful to forward the MapView.onSaveInstanceState call before adding your data to the Bundle (you did it well) :
@Override
public void onSaveInstanceState(Bundle outState) {
// Forward the call BEFORE adding our LatLng array, else it will crash :
_mapView.onSaveInstanceState(outState);
// Put your Parcelable in the bundle:
outState.putParcelableArray("myLatLng", new LatLng(0, 0) );
}
When restoring the state in the onCreate / onRestore, check if the bundle is not null, if so, get your parcel, and then remove it from the bundle before forwarding the call :
@Override
public void onCreate(Bundle savedInstanceState) {
// If the bundle is not null, get your Parcelable :
LatLng myLatLng = null;
if(savedInstanceState != null) {
myLatLng = (LatLng) savedInstanceState.getParcelable("myLatLng");
// Remove your Parcelable from the bundle, else it will crash :
savedInstanceState.remove("myLatLng");
}
// Forward the call :
_mapView.onCreate(savedInstanceState);
setUpMapIfNeeded();
}