How to use GoogleMap using MapView with Singleton approach?

287 Views Asked by At

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;
}


}
0

There are 0 best solutions below