Reuse Google Map v2 across several fragments in single Activity
Asked Answered
A

1

8

One of my activities switches the fragments that contains google map.

At first I tried to use fragment's child fragment mananger (ChildFragmentManager) to add SupportMapFragment. It works ok, but map is loaded again for each fragment, which takes a lot of time.

I have failed to detach SupportMapFragment from one fragment and attach it to another, since it somehow connected with ViewGroup where it was placed first.

So finally I decided to use plain MapView object that is create in activity and add it to viewgroup of active fragment and remove it before placing in viewgroup of another fragment.

Everything works ok except onSaveInstanceState (MapView requires manually pass call all activity lifecycle methods like onResume, onPause, onDestroy, onSaveInstanceState). When I try to call mapView.onSaveInstanceState in my activity it crushes the app.

I wonder if anybody else have successfully reused GoogleMap across several fragments?

Abulia answered 17/1, 2013 at 5:18 Comment(0)
C
-1

I'm using map fragment inside list item - I have just one fragment which is created and added to the View once and only once - I have an ExpandableListView and I'm adding it in adapter's getChildView.

Cliquish answered 23/2, 2015 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.