how to maintain fragment in a activity?

595
1
03-16-2017 01:33 AM
tanparcool
New Contributor

My design is there are 4 fragments in a activity with a page-controler align the bottom.two of them with map.

The question is:

1、use hide show fragment function:if i click the button of page-controler which with map,the previous map could be see in the new fragment and the map in new fragment can't be see,but it should be loaded because the data is print in logcat.so the new fragment can't handle my touch listener;

2、use replace fragment function it works,but it will reload without cache each click...

0 Kudos
1 Reply
AlexanderNohe1
Occasional Contributor III

I think you are having trouble with the Fragment Lifecycle (Fragments | Android Developers).  One thing to consider is that while the fragment is not visible, it can still be in the onCreate() stage of the lifecycle as this relies more on the containing activity to manage it.  Having said that, my suggestions for your questions are as follows:

1) Have you tried setting the map view in each fragment to pause when the fragment enters its onPause() callback

(MapView.pause() ) and when the fragment enters its onResume() callback, call the resume method of the mapView (MapView.resume() ) ?

2) Following the aforementioned step may relieve the symptoms you are feeling in issue 2.

0 Kudos