title: Android TabListener: onTabSelected - add fragment to back stack
body: <p>I use in my Android application a <code>TabListener</code> similar to this one: <a href="http://developer.android.com/guide/topics/ui/actionbar.html#Tabs" rel="nofollow">http://developer.android.com/guide/topics/ui/actionbar.html#Tabs</a></p>
  
  <p>My <code>onTabSelected</code> implementation:</p>
  
  <pre><code>public void onTabSelected(Tab tab, FragmentTransaction ft) {
      Fragment preInitFrag = mActivity.getFragmentManager().findFragmentByTag(mTag);
      if (preInitFrag == null) {
          mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
          ft.add(android.R.id.content, mFragment, mTag);
      } else {
          ft.attach(preInitFrag);
      }
  }
  </code></pre>
  
  <p>Every time a tab is selected, I want to add it to the back stack. How can I do this? Using the parameter <code>ft</code> with <code>ft.addToBackStack("test")</code>, it does not work. It throws a fatal exception:</p>
  
  <pre><code>java.lang.RuntimeException:
      Unable to start activity ComponentInfo{.../...BaseActivity}:
  java.lang.IllegalStateException:
      This FragmentTransaction is not allowed to be added to the back stack.
  </code></pre>