Problems when my googlemaps view activity regain t

2019-08-12 01:08发布

问题:

i have a problem with my app, it haves a lot of activitys, two of them haves googlemap views. My A activity haves a full mapview and my B activity haves a small map view. OK, when i am on the B activity and press back key somethimes until i return to my A activity, the map of my A activity shows with errors, with a black zone in the down part of the window. THis only happens when i press back from the B activity.

Because this, i need to implement/override onResume() method of A to RESTART THE ACTIVITY TO REPAINT ALL FROM SRATCH.... LIKE TO DO AGAIN ONCREATE METHOD, but i think i can't call it again... or i can?

wich code i have to put to repaint all the window from scratch ?

i tryed with all this:

-mapView.requestLayout() --> it works a little, repaints the map but with the zoom and showing the last map showed on B activity... no sense :S i dont want that. Are different maps, not have to show the same coordinates and zoom, each one have his own.

-mapView.invalidate() --> doesn't works

-mapView.postInvaldiate() --> doesn't works

回答1:

Having multiple maps (MapViews) running in the same process is not adviced. Typically, using the default configuration, all Activities (including MapActivities) run within the same process.

According to the api docs, located here http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapActivity.html

Only one MapActivity is supported per process. Multiple MapActivities running simultaneously are likely to interfere in unexpected and undesired ways.

Issues I encountered with multiple MapViews within the same process :

  • Although it appears that there are 2 different maps in the app, changes in the first map (ex: moving it to a certain position, toggling sattelite view) also got reflected in the second map, as if it was the same map.
  • On occasion, map tiles were not getting loaded properly. Portions of the map, or the complete map remained empty.
  • In Logcat, apache http connection pool errors were logged (originating from the TilesProvider)

There is a defect logged here : http://code.google.com/p/android/issues/detail?id=3756

A solution / workaround is to host your maps in different processes :

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