13

I'm currently trying to have 2 maps v2 in different tabs of a TabActivity using MapView objects. The problem arises in the following scenario:

  • tab1 with a map is displayed
  • go to tab2 in order to display another map
  • in this second tab looks like the map image from first tab is overlapping the new map. See the following picture:

TabActivity with 2 maps

On the right you can see how the first map is still displayed on top of it. The touch events are going to the new map but that doesn't really help. I spent a lot of time trying to convert our app to use fragments and run into other types of issues. One of them being http://code.google.com/p/android/issues/detail?id=40035 so that's not a good option either.

So far I haven't been able to find any workaround. To easily try various changes I wrote a simple application and made it available here: https://github.com/cristizmf/TestMapsV2. It needs only the right location for maps library project and a good maps key in manifest.

Any ideas would be greatly appreciated.

Later edit: I've logged an issue for this: https://code.google.com/p/gmaps-api-issues/issues/detail?id=5027&thanks=5027&ts=1362071369

azertiti
  • 3,150
  • 17
  • 19
  • I notice that you're using TabActivity which is deprecated. Have you tried using ViewPager instead? – Anthony Jan 29 '13 at 18:15
  • The ViewPager doesn't match our current design as it behaves differently. I tried FragmentTabHost from the compatibility library which doesn't have this problem but has others :) – azertiti Jan 29 '13 at 22:22
  • I am finding the same issue. I want to provide a pop over map in a fragment - styled like a dialog. Over another map. I can't remove the map in the background this is not a good solution for me! :( – Aiden Fry Feb 27 '13 at 11:21
  • Have you solved this problem? I´m facing same issue – Ignacio Garat Feb 04 '14 at 05:54
  • No, the issue is still open in Google's database. We changed the app's design in the meantime and this is no longer needed so I stopped looking for workarounds. – azertiti Feb 04 '14 at 10:04
  • Facing the same issue..Can anyone help?? – SweetWisher ツ Jun 03 '14 at 06:33

2 Answers2

0

We are having the exact same problem. I suspect this is caused by the fact that the new maps uses OpenGL - possibly android cant deal with having two OpenGL widgets in the view hierarchy at the same time even though one is hidden.

The only way we worked around this was to actually remove the mapview when leaving a tab, then construct a new one and add it back in when going back into the tab. This ensures that there are never two maps constructed at once.

Nasty, but it worked.

Luke Sleeman
  • 1,636
  • 1
  • 16
  • 27
  • I also tried to deallocate the map object when switching between tabs and, in my case didn't help. In the end we had to drop the maps because of the big memory leaks they have. From my testing the memory allocated by a map is never properly released. I would assume you get leaks with your solution and after a while the app will crash. – azertiti Feb 14 '13 at 10:17
  • We just did some extensive testing on the memory performance - my solution does indeed seem to leak memory. Fortunately in our situation the leak is so slow and relies of such an unusual path through the application that we have decided we can live with it. – Luke Sleeman Feb 21 '13 at 22:53
0

I ran into the same issue a few days ago and was pulling my hair out over what to do.

Originally I had my app set up with "Tabs the Fragment way" as seen here to avoid the deprecated TabActivity, and used this hack to allow me to incorporate Maps v1 in with the Fragments. It basically just masks an Activity as a Fragment.

But then switched to TabActivity further down the track for simplicity / it was better suited for the whole app. But now obviously this 2x Maps v2 fragment problem has become an issue..

So I have reverted back to "Tabs with Fragments" and just have the "hack setup" as mentioned above for each tab, which allows to have an Activity for each tab, AND having more than one Maps v2 displaying for each Tab. I haven't gone into too much depth with it, but it seems to be doing the job atm, with having just thrown some code together to test it out..

Don't know if you're still having an issue with this / this obviously isn't the most correct solution, but just thought I'd share my two cents incase you still needed it.

Cheers.

  • Thanks for your comment. We decided to drop the maps v2 until there is a stable release. I'm also waiting to see what google has to say about the ticket I logged. So far they only asked more details. I can't test your solution right now and it might work. I'm not sure about memory leaks (the maps have enough of them right now) but I'd like to avoid hacky ones as they seem to bring unexpected problems..at least in case of the maps. – azertiti Mar 14 '13 at 09:38