0

In my application I am using fragment tab-host with view pager and I am opening child fragment inside each tab. Every time I switch tab data get reloaded every time and one of the tab contains Google map, in Google map added markers programmatically but every time I switch tab it doubles the markers on map e.g. if I have added 10 markers for first time after switching once it get 20 and so on.

I have used this code to open child fragment

Used fragment page adapter with view pager

So please tellme how to stop reloading fragment.

Community
  • 1
  • 1
ankur arora
  • 151
  • 1
  • 2
  • 9

1 Answers1

0

This happens because each fragment has a lifecycle (http://developer.android.com/guide/components/fragments.html), and when you switch tab data the fragment is destroyed and another is created.

You are using fragments with view pager and this is controlled by a Parent Activity, so you can move the code to load the map to the Activity, and just use the fragment to display the data stored inside the activity.

You can get the parent activity with this code inside your fragment:

(YourActivity) this.getActivity();