title: Android ActionBar tabs set initially selected tab
body: <p>I have noticed that when using </p>
  
  <pre><code>actionBar.setSelectedNavigationItem(x)
  </code></pre>
  
  <p>in the onCreate() method of my Activity, the tab item at position 0 is always selected first and then the tab item at position x is loaded. This means that (since I'm using Fragments) 2 Fragments are loaded. One of them being unnecessary...</p>
  
  <p>Here's my code:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      // Determine which bundle to use; either the saved instance or a bundle
      // that has been passed in through an intent.
      Bundle bundle = getIntent().getExtras();
      if (bundle == null) {
          bundle = savedInstanceState;
      }
  
      // Initialize members with bundle or default values.
      int position;
      if (bundle != null) {
          position = bundle.getInt("selected_tab");
      } else {
          position = 0;
      }
  
      // Set the tabs.
      ActionBar actionBar = getActionBar();
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
      Tab tab = actionBar
              .newTab()
              .setText("Tab 1")
              .setTabListener(
                      new TabListener&lt;RendersGridFragment&gt;(this, "1",
                              RendersGridFragment.class));
      actionBar.addTab(tab);
  
      tab = actionBar
              .newTab()
              .setText("Tab 2")
              .setTabListener(
                      new TabListener&lt;RendersGridFragment&gt;(this, "2",
                              RendersGridFragment.class));
      actionBar.addTab(tab);
  
      tab = actionBar
              .newTab()
              .setText("Tab 3")
              .setTabListener(
                      new TabListener&lt;RendersGridFragment&gt;(this, "3",
                              RendersGridFragment.class));
      actionBar.addTab(tab);
  
      actionBar.setSelectedNavigationItem(position);
  }
  </code></pre>
  
  <p>It seems that the tab at position 0 is selected initially by default. But, as you can see, I'm passing bundles to make sure the last selected tab is still selected when the activity onCreate() method is run again.</p>
  
  <p>For example,
  if the last selected tab is at position 2, the onCreate() runs and the tab at position is 0 is loaded, then the tab at position 2 is loaded.</p>
  
  <p>How can I make sure the ActionBar doesn't select tab at position 0 first when using actionBar.setSelectedNavigationItem(position).</p>