I am trying to use MapView with singleton approach.
Here I create MapView once and does its mapViewSingletonInstance.onCreate(savedInstance) only one time. After this I try to use it doing anotherMapViewObject.addView(mapViewSingletonInstance)
But this only works one time. After adding to one mapView with anotherMapView it does not work.
public class GoogleMapSingleton{
private static GoogleMapSingleton googleMapSingleton;
private static MapView singletonMapView;
private GoogleMapSingleton()
{
}
public static GoogleMapSingleton GoogleMapSingletonInstance(Bundle savedInstanceState, Context context)
{
if(googleMapSingleton == null){
singletonMapView = new MapView(context);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
singletonMapView.setLayoutParams(lp);
singletonMapView.onCreate(savedInstanceState);
singletonMapView.onResume();
singletonMapView.getMap();
googleMapSingleton = new GoogleMapSingleton();
}
return googleMapSingleton;
}
/**
* @return the singletonMapView
*/
public MapView getSingletonMapView() {
return singletonMapView;
}
}