Switching between tabs with Fragments
<p>I seem to be running into a problem following the tutorials on the Android site regarding fragments.  Using my GoogleFu, I found out that there are support issues regarding inserting fragments into activities via an <code>actionTab</code> layout regarding version numbers (i.e. different Fragment objects).</p>

<p>It seems I cannot use any of the <code>.attach(Fragment)</code>, <code>detach(Fragment)</code> etc... even though I am passing in the appropriate Fragment into the constructor.</p>

<p>My API level is 13</p>

<pre><code>public class MainActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //add in my fragments
    Fragment fragmentA = (Fragment) new ViewFilesFragment();
    Fragment fragmentB = (Fragment) new DownloadFragment();
    Fragment fragmentC = (Fragment) new UploadFragment();

    //set the action bar tabs
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(false);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    //Change the fragment depending on the action by the end user
     Tab tab = actionBar.newTab()
                .setText(R.string.title_Items)
                .setTabListener(new TabListener(this, "FILES", fragmentA));
        actionBar.addTab(tab);

        tab = actionBar.newTab()
                .setText(R.string.title_Downloads)
                .setTabListener(new TabListener(this, "DOWNLOAD", fragmentB));
            actionBar.addTab(tab);

        tab = actionBar.newTab()
            .setText(R.string.title_Upload)
            .setTabListener(new TabListener(this, "UPLOAD", fragmentC));
        actionBar.addTab(tab);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // This is called when the Home (Up) button is pressed
            // in the Action Bar.
            Intent parentActivityIntent = new Intent(this, MainActivity.class);
            parentActivityIntent.addFlags(
                    Intent.FLAG_ACTIVITY_CLEAR_TOP |
                    Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(parentActivityIntent);
            finish();
        case R.id.menuBtn_logOut:
            finish();

    }
    return super.onOptionsItemSelected(item);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    final ActionBar actionBar = getActionBar();
    // Specify that tabs should be displayed in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    return true;
}
public static class TabListener&lt;T extends android.support.v4.app.Fragment&gt; implements ActionBar.TabListener {
    private Fragment mFragment;
    private final Activity mActivity;
    private final String mTag;
    private final Class&lt;T&gt; mClass;

    /** Constructor used each time a new tab is created.
      * @param activity  The host Activity, used to instantiate the fragment
      * @param tag  The identifier tag for the fragment
      * @param clz  The fragment's Class, used to instantiate the fragment
      */
    public TabListener(Activity activity, String tag, Class&lt;T&gt; clz) {
        mActivity = activity;
        mTag = tag;
        mClass = clz;
    }

    /* The following are each of the ActionBar.TabListener callbacks */

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // Check if the fragment is already initialized
        if (mFragment == null) {
            // If not, instantiate and add it to the activity
            mFragment = Fragment.instantiate(mActivity, mClass.getName());
            ft.add(android.R.id.content, mFragment, mTag);
        } else {
            // If it exists, simply attach it in order to show it
            ft.attach(mFragment);
        }
    }

    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        if (mFragment != null) {
            // Detach the fragment, because another one is being attached
            ft.detach(mFragment);
        }
    }

    public void onTabReselected(Tab tab, FragmentTransaction ft) {
        // User selected the already selected tab. Usually do nothing.
    }
}
   @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        //Handle the back button
        if(keyCode == KeyEvent.KEYCODE_BACK) {
            //Ask the user if they want to quit
            new AlertDialog.Builder(this)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle("Quit World Share")
            .setMessage("Do you really want to quit?")
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {

                    //Stop the activity
                    MainActivity.this.finish();    
                }

            })
            .setNegativeButton("Cancel", null)
            .show();

            return true;
        }
        else {
            return super.onKeyDown(keyCode, event);
        }
    }
}
</code></pre>
