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.
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: