销毁地图视图

发布于 2024-10-19 10:33:52 字数 470 浏览 4 评论 0原文

我有一个 MapActivity,您可以在 MapView(Google 地图)和 OfflineMapView(我的课程,显示之前下载到 SD 卡的地图)之间切换。在地图之间切换时,我想完全销毁并创建地图视图,以便内存中只有一个地图视图。我想要这个有两个原因:

  1. 我的 OfflineMapView 占用了大部分可用内存来缓存图块。
  2. 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:

  1. My OfflineMapView takes most of available memory for caching tiles.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间☆小暴躁 2024-10-26 10:33:52

使用 ActivityGroup 作为您的 Activity 类,并让它为每种类型的地图启动和停止子活动。例如,要获取 Google 地图的视图:

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 及其线程。

请注意,我发现 LocalActivityManager.destroyActivity() 有问题,因此我在示例中使用了 LocalActivityManager().removeAllActivities() 因为它确实适用于这种情况。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文