I resolved
There is an issue i think. Every time that you turn the device on landscape, the Marker
's MarkerInfoWindow
has an old reference to the Context
and that's why the bubble is not shown on click. (maybe can be fixed using fragments...)
Just rewrite the class and when recreate the markers you just pass the new reference to the context.
The code:
public class myMarker extends Marker implements Parcelable{
InfoWindow i;
MapView map;
static Context context=null;
static MarkerInfoWindow ma=null;
public myMarker(MapView mapView) {
super(mapView);
Context c=mapView.getContext();
/*IF THE CONTEXT CHANGES, I KEEP MY NEW (RECREATED) mapView AND I SET A NEW static
MarkerInfoWindow OTHERWISE AT ANY CASE I SET THE static markerInfoWindow TO THE MARKER */
if(context==null||context!=c){
i=super.mInfoWindow;
map=mapView;
context=c;
String packageName=context.getPackageName();
int layoutResId=context.getResources().getIdentifier("layout/bonuspack_bubble",null,packageName);
ma=new MarkerInfoWindow(layoutResId, mapView);
}
super.setInfoWindow(ma);
}
...
}
And the onRestore, when you reload the map in landscape, after onSave:
/*@ onRestore i keep my old markers and i create new markers with same info but with new mapView(new Context)*/
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
if (savedInstanceState != null) {
/*NEW MARKERS EQUALS TO THE OLD BUT WITH NEW MAP (NEW CONTEXT)
...AND NO YOU CANT JUST UPDATE THE CONTEXT*/
ArrayList<myMarker> markers2;
markers2 = savedInstanceState.getParcelableArrayList("MARKERS");
if(markers2!=null){
for (int i=0;i<markers2.size();i++){
myMarker m=new myMarker(map);
m.setTitle(markers2.get(i).getTitle());
m.setImage(markers2.get(i).getImage());
m.setPosition(markers2.get(i).getPosition());
m.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
markers.add(m);
map.getOverlays().add(m);
}
}
map.invalidate();
}
else markers=new ArrayList<myMarker>();
}