销毁地图视图
我有一个 MapActivity,您可以在 MapView(Google 地图)和 OfflineMapView(我的课程,显示之前下载到 SD 卡的地图)之间切换。在地图之间切换时,我想完全销毁并创建地图视图,以便内存中只有一个地图视图。我想要这个有两个原因:
- 我的 OfflineMapView 占用了大部分可用内存来缓存图块。
- Google MapView 有一些附加线程,当 OfflineMapView 可见时我不想运行这些线程。
我尝试从布局中删除 MapView 并将对它的引用设为 null,但是当我想再次显示它时,我收到一个异常,说 MapActivity 只能有一个 MapView。
编辑: Google MapView 的存在(可见性设置为 GONE)不会对 OfflineMapView FPS 产生任何影响。我也没有收到任何 OutOfMemoryErrors 错误。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
ActivityGroup
作为您的Activity
类,并让它为每种类型的地图启动和停止子活动。例如,要获取 Google 地图的视图:销毁它:
并对离线地图执行相同的操作。这应该完全停止 MapActivity 及其线程。
请注意,我发现
LocalActivityManager.destroyActivity()
有问题,因此我在示例中使用了LocalActivityManager().removeAllActivities()
因为它确实适用于这种情况。Use
ActivityGroup
as yourActivity
class and have it start and stop sub-activities for each type of map. For example, to get the view for the Google Map:to destroy it:
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 usedLocalActivityManager().removeAllActivities()
in the example since it does work for this case.