title: Strange onPause(), onResume() behaviour in fragments
body: <p>The application has a main activity (MainActivity.java) with three tabs (fragments). I can navigate between them using the swipe left (riht) or clicking on a specific tab. </p>
  
  <p>Upon starting the application, the 1st fragment is shown. </p>
  
  <p>If I go to the 2nd fragment from the 1st fragment and then back to the 1st fragment, nothing happens (onResume() of the 1rd fragment isn't called), so it doesn't refresh it's content.</p>
  
  <p>If I go to the 3rd fragment from the 1st fragment and then directly back to the 1st fragment, the onCreateView() of fragment1 is created and it's onResume() is called, which is correct.</p>
  
  <p>If I go from the 3rd fragment to the 2nd fragment, the onCreateView() and onResume() of fragment1 are called, but not the onCreateView of fragment2.</p>
  
  <p>I guess the logic in MainActivity isn't right, so I would kindly ask someone to take a look and tell me what could be wrong.</p>
  
  <p>MainActivity.java:</p>
  
  <pre><code>public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
  
  CollectionPagerAdapter mCollectionPagerAdapter;
  public TTSocket socket;
  DBHandler db;
  public String logged_user;
  private LogedinPerson person;
  ViewPager mViewPager;
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.main);
  
      Bundle extras = getIntent().getExtras();
      logged_user = extras.getString("logged_user");
      socket = TTSocket.getInstance();
      socket.currentRef = this;
  
      db = new DBHandler(this);
      person=db.getLogedInPerson();
  
      socket.dbHandler=db;
      socket.person=person;
  
      if(!socket.isInit){
          String typeInitStr = "{\"Type\":\"Init\", \"UserId\":\""+ person.getUserId() +"\"}";
          socket.Send(typeInitStr);
      }
  
  
      mCollectionPagerAdapter = new CollectionPagerAdapter(getSupportFragmentManager());
  
      // Set up action bar.
      final ActionBar actionBar = getActionBar();
  
      // Specify that we will be displaying tabs in the action bar.
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
      // Set up the ViewPager, attaching the adapter and setting up a listener
      // for when the
      // user swipes between sections.
      mViewPager = (ViewPager) findViewById(R.id.pager);
      mViewPager.setAdapter(mCollectionPagerAdapter);
      mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
              @Override
              public void onPageSelected(int position) {
              Log.d("TEST",position+"");
              // the corresponding tab.
              // We can also use ActionBar.Tab#select() to do this if
              // we have a reference to the Tab
              actionBar.setSelectedNavigationItem(position);
              }
          });
  
      // For each of the sections in the app, add a tab to the action bar.
      for (int i = 0; i &lt; mCollectionPagerAdapter.getCount(); i++) {
          // Create a tab with text corresponding to the page title defined by
          // the adapter.
          // Also specify this Activity object, which implements the
          // TabListener interface, as the
          // listener for when this tab is selected.
          if(i == 0){
              actionBar.addTab(actionBar.newTab()
                      .setIcon(R.drawable.messages)
                      .setTabListener(this));
  
          }else if(i == 1){
              actionBar.addTab(actionBar.newTab()
                      .setIcon(R.drawable.contacts)
                      .setTabListener(this));
          }else{
              actionBar.addTab(actionBar.newTab()
                      .setIcon(R.drawable.history)
                      .setTabListener(this));
          }
      }
  }
  
  @Override
  protected void onResume() {
      // TODO Auto-generated method stub
      super.onResume();
  
      socket.currentRef = this;
      socket.dbHandler=db;
      socket.person=person;
  
      //mCollectionPagerAdapter.notifyDataSetChanged();
  }
  
  public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
  }
  
  public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
  // When the given tab is selected, switch to the corresponding page in
  // the ViewPager.
  mViewPager.setCurrentItem(tab.getPosition());
  }
  
  public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
  }
  
  /**
   * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
   * one of the primary sections of the app.
   */
  public class CollectionPagerAdapter extends FragmentPagerAdapter {
  
  final int NUM_ITEMS = 3; // number of tabs
  
  public CollectionPagerAdapter(FragmentManager fm) {
      super(fm);
  }
  /*
  @Override
  public Fragment getItem(int i) {
      Fragment fragment = new TabFragment();
      Bundle args = new Bundle();
      args.putInt(TabFragment.ARG_OBJECT, i);
      fragment.setArguments(args);
      return fragment;
  }
  */
  @Override  
  public Fragment getItem(int position) {  
  
      Fragment fragment = new Fragment(); 
      Bundle args = new Bundle();
      args.putInt(TabFragment.ARG_OBJECT, position);
      switch (position) {  
          case 0:  
              Log.i("Fragment", "0");
              fragment =  new Tab1Fragment();
              fragment.setArguments(args);
              return fragment; 
          case 1:  
              Log.i("Fragment", "1");
              fragment =  new Tab2Fragment();  
              fragment.setArguments(args);
              return fragment; 
          case 2:  
              Log.i("Fragment", "2");
              fragment =  new Tab3Fragment();   
              fragment.setArguments(args);
              return fragment;  
          default:  
              break;  
      }
  
      return fragment;
  }
  
  @Override
  public int getCount() {
      return NUM_ITEMS;
  }
  
  @Override
  public CharSequence getPageTitle(int position) {
      String tabLabel = null;
      switch (position) {
      case 0:
      tabLabel = getString(R.string.label1);
      break;
      case 1:
      tabLabel = getString(R.string.label2);
      break;
      case 2:
      tabLabel = getString(R.string.label3);
      break;
      }
  
      return tabLabel;
  }
  }
  
  /**
   * A fragment that launches other parts of the demo application.
   */
  public static class TabFragment extends Fragment {
  
  public static final String ARG_OBJECT = "object";
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
  
      Bundle args = getArguments();
      int position = args.getInt(ARG_OBJECT);
  
      int tabLayout = 0;
      switch (position) {
      case 0:
          tabLayout = R.layout.tab1;
          break;
      case 1:
          tabLayout = R.layout.tab2;
          break;
      case 2:
          tabLayout = R.layout.tab3;
          break;
      }
  
      View rootView = inflater.inflate(tabLayout, container, false);
  
      return rootView;
  }
  }
  
  
  }
  </code></pre>