Destroy MapView

I have a MapActivity where you can switch between MapView (Google Maps) and OfflineMapView (my class shows a map previously loaded on an SD card). When switching between cards, I want to completely destroy and create cards so that only one map view is displayed in memory. I want this for two reasons:

  • My standalone MAPView takes up most of the available cache memory.
  • Google MapView has associated streams that I don’t want to run when the OfflineMapView function is visible.

I tried to remove the MapView from the layout and null my link to it, but when I want to show it again, I get an exception saying that MapActivity can only have one MapView.

EDIT: The presence of Google MapView (visibility - GONE) has no effect on the offline mode of FPS. I also did not get any OutOfMemoryErrors.

+1
source share
1 answer

Use ActivityGroupas your class Activityand start and stop sub-actions for each type of map. For example, to get a view for Google Maps:

Intent intent = new Intent(this, GoogleMapActivity.class);
Window window = getLocalActivityManager().startActivity("google-map", intent);
View googleMapView = window.getDecorView();
container.addView(googleMapView);

to destroy it:

container.removeView(googleMapView);
getLocalActivityManager().removeAllActivities();

and do the same with your offline map. This should completely stop the MapActivitythreads.

Note that I found an LocalActivityManager.destroyActivity()error, so I used LocalActivityManager().removeAllActivities()in the example, since it works for this case.

+4
source

All Articles