销毁的MapView [英] Destroy MapView

查看:614
本文介绍了销毁的MapView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MapActivity在那里你可以图形页面(谷歌地图)和OfflineMapView之间切换(我的课,将显示在地图previously下载到SD卡)。在地图之间切换我要彻底摧毁,并创建地图的意见,以便只有一个地图视图是在内存中。我想这有两个原因:

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:


  1. 我OfflineMapView最需要的可用内存用于缓存的瓷砖。

  2. 谷歌MapView获得一些附加的线程,我不希望运行时,OfflineMapView是可见的。

我试图从布局中删除的MapView和空我提到它,但是当我想再次显示它我得到一个异常说MapActivity只能有一个图形页面。

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.

编辑:
谷歌MapView类的presence(可见性设置为GONE)不会对OfflineMapView FPS任何影响。我没有得到任何OutOfMemoryError异常无论是。

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.

推荐答案

使用的ActivityGroup 为你的活动类和有它启动和停止子活动为每种类型的地图。例如,获得了谷歌地图的视图:

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

要摧毁它:

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

和做同样的离线地图。这应该完全停止 MapActivity 和它的线程。

and do the same with your offline map. This should completely stop the MapActivity and it's threads.

请注意,我已经找到 LocalActivityManager.destroyActivity()是马车,所以我用 LocalActivityManager()。removeAllActivities()中的例子,因为它为这种情况下工作。

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.

这篇关于销毁的MapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆