Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance of multiple MapFragments (Android Map API v2)

I searched the docs of the new Google Android Map API v2, but didn't find anything about it. Before v2 we (officially) couldn't properly display more than one map per application (process). I assume that with MapFragment implementation it's no longer an issue. I also know, that Fragments can be self-contained since API 17. And, last but not least, there is compatibility package, which makes it possible to port it all back to at least API 8 (in API 7, there's no OpenGL 2.0 so the maps wouldn't work afaik).

Sa I have all the ingredients to port my app to Maps API v2 and implement the following scenario: ViewPager contains Fragments and each of them contains a MapFragment.

But should I do it? I mean, would I face performance issues if I had e.g. 20 Fragments containing MapFragments in a ViewPager?

If you found anything that addresses my concern in the docs or somewhere else, please tell me.


EDIT: Example usage: Let's imagine a screen containing informations about some specific item - place, event, article. Also let's imagine that, among other informations, it must contain a map to be fully functional. But I would like the user to be able to swipe to another item if he wants. Each item has its own map.

Side note: I know that I can implement one map outside the ViewPager and just update it based on the currently displayed item, but it's not what I'm looking for - it's not user-centered design.


Possible solution (but not checked yet). ViewPager only keeps a few (default - 3) Fragments in it's cache and recreates them when they're about to show up, so there won't be much memory overhead as only a few MapFragments are needed. The performance problem may be the MapFragment inflation which is quite heavy, I believe - but that can be solved with recycling of MapFragments.


So why won't I implement it if I believe it will work nice? There's another problem which makes it impossible to move MapFragments without the app look like it's broken. See this.

like image 608
Michał Klimczak Avatar asked Dec 06 '12 10:12

Michał Klimczak


2 Answers

You could easily test it but my guess is that it would very much depend on the phone as Maps still is fairly heavy to run.

That said I'd never recommend this kind of user navigation. A map can already be swiped at so why would you add ViewPager swipe as well? This would make a very confusing user experience. If you want to switch between different views/point of interests you should add buttons (overflow menu buttons preferred as in the navigation app) or something similar that helps the user navigate around.

like image 91
Warpzit Avatar answered Oct 22 '22 19:10

Warpzit


Yes, you definitely would run into performance issues because ViewPager doesn't employ view recycling by default; you can even bloat it with ImageViews let alone MapFragments.

As far as caching and recreating fragments in ViewPager - there's a HorizontalListView lib that'd probably save you the effort as it does support view recycling.

like image 45
Ivan Bartsov Avatar answered Oct 22 '22 19:10

Ivan Bartsov