title: Why does the fragment's onCreateView, onCreate, onActivityCreated are called
body: <p>I have an app, that deals with fragments and ViewPager. I have three fragments in a ViewPager.  When you switch between them, it always causes the other two fragments to call their's onCreateView methods. How to do it only once, only when FragmentActivity is created???
  I've read some questions and tried the solutions, but the fragments still have the same behavior.</p>
  
  <p><a href="https://stackoverflow.com/questions/15005937/listfragment-oncreate-called-twice">ListFragment onCreate called twice</a><br>
  <a href="https://stackoverflow.com/questions/7223166/oncreate-and-oncreateview-invokes-a-lot-more-than-required-fragments">onCreate() and onCreateView() invokes a lot more than required (Fragments)</a>  </p>
  
  <p>Here is some code, if it helps you, guys:</p>
  
  <p>MainActivity: </p>
  
  <pre><code>public class StartingActivity extends FragmentActivity implements View.OnClickListener {
  ViewPager viewPager;
      CirclePageIndicator pageIndicator;
  
      Button discount;
      Button qrCode;
      Button pay;
      TabHost tabHost;
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.starting_layout);
          viewPager = (ViewPager) findViewById(R.id.pager);
  
          if (savedInstanceState == null) {
  
              Fragment firstPage = Fragment.instantiate(this, FindTovarFragment.class.getName());
              Fragment secondPage = Fragment.instantiate(this, MainWindowActivity.class.getName());
              Fragment thirdPage = Fragment.instantiate(this, MapActivity.class.getName());
  
              if ((firstPage != null &amp;&amp; !firstPage.isDetached())|| (secondPage != null &amp;&amp; !secondPage.isDetached()) || (thirdPage != null &amp;&amp; !thirdPage.isDetached())) {
  
              List&lt;Fragment&gt; viewPagerFragments = new ArrayList&lt;Fragment&gt;();
              viewPagerFragments.add(firstPage);
              viewPagerFragments.add(secondPage);
              viewPagerFragments.add(thirdPage);
  
  
              PageAdapter pageAdapter = new PageAdapter(getSupportFragmentManager(), viewPagerFragments);
  
              viewPager.setAdapter(pageAdapter);
  
              pageIndicator = (CirclePageIndicator) findViewById(R.id.circle);
              pageIndicator.setViewPager(viewPager);
              pageIndicator.setCurrentItem(pageAdapter.getCount() - 2);
              }
          }
  
  }
  </code></pre>
  
  <p>MapActivity: </p>
  
  <pre><code>public class MapActivity extends Fragment implements OnMyLocationListener {
  
      //Тэг для логов
      private static final String TAG = "MapActivity";
      List&lt;Address&gt; addressList;
      private static final String STRING_LOCATION = "";
  
      ArrayList&lt;TorgCentr&gt; randomTorgCentr;
      ArrayList&lt;String&gt; torgCentrNames;
  
      Context context;
      AutoCompleteTextView searchTorgCentr;
      OverlayManager overlayManager;
      MapController mapController;
      TextView textView;
      double longitude;
      double latitude;
      double itemLongitude;
      double itemLatitude;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          Log.d(TAG, "MapActivity onCreateView");
  
  
          View view = (LinearLayout) inflater.inflate(R.layout.map_layout, container, false);
          final MapView mapView = (MapView) view.findViewById(R.id.map);
          textView = (TextView) view.findViewById(R.id.searchlocation);
          searchTorgCentr = (AutoCompleteTextView) view.findViewById(R.id.autoCompleteTextView);
  
          mapView.showBuiltInScreenButtons(true);
          mapController = mapView.getMapController();
          context = getActivity();
          return view;
      }
  
      @Override
      public void onResume() {
          super.onResume();
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Log.d(TAG, "MapActivity onCreate");
  
      }
  
      public void onActivityCreated(Bundle savedInstanceState) {
          Log.d(TAG, "MapActivity onActivityCreated");
          context = getActivity();
  
          SetRightMapDisplayAddress rightMapDisplayAddress = new SetRightMapDisplayAddress();
          rightMapDisplayAddress.execute(STRING_LOCATION);
  
          DownloadSuperMarketsArray superMarketsArray = new DownloadSuperMarketsArray();
          superMarketsArray.execute();
  
          overlayManager = mapController.getOverlayManager();
          overlayManager.getMyLocation().setEnabled(false);
  
          super.onActivityCreated(savedInstanceState);
      }
  </code></pre>
  
  <p>Second Fragment:</p>
  
  <pre><code>public class MainWindowActivity extends Fragment {
  
      private static final String TAG = "MainWindowActivity";
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          Log.d(TAG, "MainWindowActivity onCreateView");
          View view = (RelativeLayout) inflater.inflate(R.layout.main_window_layout, container, false);
          if (container == null) {
              return null;
          }
          return view;
      }
  }
  </code></pre>
  
  <p>And the third one: </p>
  
  <pre><code>public class FindTovarFragment extends Fragment {
  
      private static final String TAG= "FindTovarFragment";
  
      Context context;
      ArrayList&lt;Category&gt; categories;
      Spinner categoryContainer;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          Log.d(TAG, "FindTovarFragment onCreateView");
  
          View view = (LinearLayout) inflater.inflate(R.layout.find_tovar_main_layout, container, false);
          categoryContainer = (Spinner) view.findViewById(R.id.category);
  
          return view;
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          Log.d(TAG, "FindTovarFragment onActivityCreated");
          DownloadCategory downloadCategory = new DownloadCategory();
          downloadCategory.execute();
      }
  </code></pre>
  
  <p>Logs for MapActivity: </p>
  
  <pre><code>06-20 11:06:37.709: DEBUG/MapActivity(1290): MapActivity onCreate
  06-20 11:06:37.709: DEBUG/MapActivity(1290): MapActivity onCreateView
  06-20 11:06:38.509: DEBUG/MapActivity(1290): MapActivity onActivityCreated
  </code></pre>
  
  <p>Then again and again: </p>
  
  <pre><code>06-20 11:07:53.239: DEBUG/MapActivity(1290): MapActivity onCreate
  06-20 11:07:53.239: DEBUG/MapActivity(1290): MapActivity onCreateView
  06-20 11:07:53.429: DEBUG/MapActivity(1290): MapActivity onActivityCreated
  06-20 11:08:23.029: DEBUG/MapActivity(1290): MapActivity onCreate
  06-20 11:08:23.039: DEBUG/MapActivity(1290): MapActivity onCreateView
  06-20 11:08:23.269: DEBUG/MapActivity(1290): MapActivity onActivityCreated
  </code></pre>
  
  <p>Thank you very much in advance.</p>