Issue
I have a MapActivity where you can switch between MapView (Google Maps) and OfflineMapView (my class, shows a map previously downloaded to SD card). When switching between maps I want to completely destroy and create the map views so that only one map view is in the memory. I want this for 2 reasons:
- My OfflineMapView takes most of available memory for caching tiles.
- Google MapView has some attached threads which I don't want running when OfflineMapView is visible.
I tried to remove the MapView from layout and null my reference to it but when I want to show it again I get an exception saying that MapActivity can have only one MapView.
EDIT: The presence of Google MapView (visibility is set to GONE) doesn't have any effect on OfflineMapView FPS. I didn't get any OutOfMemoryErrors either.
Solution
Use ActivityGroup
as your Activity
class and have it start and stop sub-activities for each type of map. For example, to get the view for the Google Map:
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 MapActivity
and it's threads.
Note that I have found LocalActivityManager.destroyActivity()
to be buggy, so I used LocalActivityManager().removeAllActivities()
in the example since it does work for this case.
Answered By - Jason Hanley
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.