如何使用多个MapActivities /每个Android应用程序MapViews /工艺多个、如何使用、应用程序、工艺

2023-09-11 12:47:18 作者:屹立在这世上

我已经写了一个 MapActivity 类,它是能够显示一组位置,以及单一的地方。在启动时,应用程序创建 MapActivity 这样的一个实例,并显示多个地方。如果用户点击了某个地方,那么新的活动启动,显示所选地点的详细信息。此活动有一个菜单项,允许用户观看在地图上的位置 - 这会导致在 MapActivity 创建,除了现在只有这一个地方的一个新实例被显示。

现在的问题是,如果用户返回到第一个 MapActivity (一个显示多个地方)的砖将不再装+有时OutOfMemoryError异常是遇到过。

根据Android的JavaDoc,那么只可能有一个 MapActivity 每个进程。不过,我不希望我的定义 MapActivity 作为singleInstance / singleTask,因为用户应该总是能够导航回到第一MapActivity显示多个地方。

我已经看到了谷歌应用程序的地方(这已经与谷歌地图4.4)的Andr​​oid使用多个 MapActivity 实例。这怎么可能?我怎么能实现它在我的应用程序?

解决方案   

据了Android的JavaDoc,它   只可能有一个   每类MapActivity

这不是每类中的一个图来看,它的每个进程。

据了解,你可能会在一个进程中使用多个mapviews时遇到的一些问题。通常是这样的话(在一个过程中你的应用程序中运行),如果你不配置任何具体。 你可以尽管使用android:在你的清单过程中的属性分配给您的活动还:

 <活动机器人:activity.directory.MapView1名称=安卓程序=:MapView1>

<活动机器人:activity.directory.MapView2名称=安卓程序=:MapView2>
 

这种方式,你必须运行在单独的进程的活动,效果很好,如果你不跨越性活动中使用任何共享静态变量。

也看到了Android的bug跟踪系统上的错误的讨论:

http://$c$c.google.com/p/android/issues/detail?id=3756

I have written one MapActivity class that is able to display a set of places as well as single places. On startup, the application creates an instance of this MapActivity and displays multiple places. If the user clicks on a certain place, then a new Activity is launched that shows the details of the selected place. This activity has a menu item that allows the user to view the place on a map - this causes that a new instance of the MapActivity is created, except that now only this single place is displayed.

Android使用Google Map浅谈

The problem now is that if the user navigates back to the first MapActivity (the one that shows multiple places) the tiles won't be loaded anymore + sometimes OutOfMemoryErrors are encountered.

According to the Android JavaDocs, it is only possible to have one MapActivity per process. However, I don't want to define my MapActivity as a singleInstance/singleTask, since the user should always be able to navigate back to the first MapActivity that shows multiple places.

I have seen that the Google Places app (which has come with Google Map 4.4) for Android uses multiple MapActivity instances. How is this possible? And how can I achieve it in my application?

解决方案

According to the Android JavaDocs, it is only possible to have one MapActivity per class

It's not one map view per class, it's per process.

It's known that you might experience some issues when using multiple mapviews in one process. Usually this is the case (your app running in one process) if you don't configure anything specific. You could though use the android:process attribute in your manifest to assign to your acitivites:

<activity android:name=".activity.directory.MapView1" android:process=":MapView1">

<activity android:name=".activity.directory.MapView2" android:process=":MapView2">

This way you have the activities running in separate processes, which works well if you don't use any shared static variables across activities.

Also see the discussion on the bug in the android bug tracker:

http://code.google.com/p/android/issues/detail?id=3756