How to use multiple MapActivities/MapViews per Android application/process
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
How to use a single MapView across several MapActivities
Fixed my own problem...
When the MapFragment is being resumed I just had to remove all views from the fragment and from the mapview's parent, and then add the mapview to the fragment:
@Override
public void onResume() {
super.onResume();
resumed++;
if (resumed > 0) {
ViewGroup view = (ViewGroup) this.getView();
view.removeAllViews();
ViewGroup parentViewGroup = (ViewGroup) app.mapViewContainer.getParent();
if (parentViewGroup != null) {
parentViewGroup.removeAllViews();
}
view.addView(app.mapViewContainer);
}
}
Multiple map views?
Assuming you are talking about showing both at the same time, it doesn't appear to be possible. See
How to Make 2 MapView on One Activity
Updated to respond to comment.
Per the Google Map API MapActivity, "Only one MapActivity is supported per process. Multiple MapActivities running simultaneously are likely to interfere in unexpected and undesired ways." So even if you have two different MapActivities you have to deal with the Process Lifecycle, where perhaps one activity is visible and the other activity is background and that is where you are getting problems.
2nd Update
So according to this thread Limitations of the MapView and MapActivity one commenter put a separate activity between two MapActivities and was able to make it work, but otherwise you will have to use overlays/find a way to make your app work with only one MapActivity.
Technique for running multiple MapActivities in the same process
I would guess that the only reason to not do this would be performance. The map activity can already be a bit of a dog, especially when starting it, so if you find yourself allocating and deallocating the view frequently, this might perform pretty poorly. However, its really dependent on how often the view will be created and removed, which depends entirely on behavioral aspects of your application.
Unexpected connection between two MapView
If you're using multiple MapViews per process, it might conflict.
https://developers.google.com/maps/documentation/android/reference/com/google/android/maps/MapActivity
Only one MapActivity is supported per process. Multiple MapActivities
running simultaneously are likely to interfere in unexpected and
undesired ways.
And also see my reply on How to use multiple MapActivities/MapViews per Android application/process
But as SpK commented, please provide the code of your activities.
Multiple maps (with swiping) in a MapActivity in android
You can have only one Mapview per map activity, however, you can have multiple map activities in one application, which in your case wouldnt be a very ideal solution.
What you should do instead of having a totally new mapview for an address, you could have a different set of overlays for them. This way you'll only need to change the set of overlays when you want to view map details for another address. Besides being possible to make this with Android, its much more optimal than having multiple mapviews.
Android - Two Maps in one App
Having two maps in one app produces many weird application behavior. For example, Ive had overlays from one map show up in the second map.
That said, it is possible to have two maps in one application without the above happening. What you need to do is to specify a new process for the second mapview:
<activity
android:label="@string/app_name"
android:name=".SecondMapActivityName"
android:process=":SecondMapProcess"
>
</activity>
The above code lies in the manifest and is for the activity containing the second MapView. This way a new process starts for this activity within the same app and both your maps behave as they should.
Related Topics
Android:Call Activity of Another Application
How Can Make My Viewpager Load Only One Page at a Time Ie Setoffscreenpagelimit(0);
Cursor Adapter and SQLite Example
How to Get an Uri of an Image Resource in Android
Best Practice for Defining Button Events in Android
Android SQLite Issue - Table ... Has No Column Named
Android Pendingintent Extras, Not Received by Broadcastreceiver
Setonitemclicklistener on Custom Listview
Facebook - "Cannot Query Users by Their Username" Solution
Ics Android Enable Gps Programmatically
How Do Mpandroidchart Renderers Work and How to Write a Custom Renderer
Android Http Connection Exception
What Is the Class R in Android
How to Determine If One of My Activities Is in the Foreground
Phonegap - Forcing Landscape Orientation
Display Badge on Top of Bottom Navigation Bar's Icon
Getlastknownlocation Always Return Null After I Re-Install the APK File via Eclipse
How to Make Notification Intent Resume Rather Than Making a New Intent