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?