tags:

views:

65

answers:

1

I'm working on adding a tab to an application, but the last two tabs (regardless of order) are launching the same activity. If I go down to two tabs they both work correctly, but when I add the third the last two result in the same activity launching. Any suggestions?

public void uiConnected() {
    Log.d(TAG, "UI Connected");

    tabHost.clearAllTabs();

    intent.setClass(this, NowPlayingActivity.class);
    spec = tabHost.newTabSpec("nowplaying").setIndicator("Now Playing").setContent(intent);
    tabHost.addTab(spec);

    intent.setClass(this, PlaylistActivity.class);
    spec = tabHost.newTabSpec("playlist").setIndicator("Playlist").setContent(intent);
    tabHost.addTab(spec);

    intent.setClass(this, LibraryActivity.class);
    spec = tabHost.newTabSpec("library").setIndicator("Library").setContent(intent);
    tabHost.addTab(spec);

    if (MPDApplication.DEBUG) {
        tabHost.setCurrentTabByTag(app.sp.getString(AppPreferenceActivity.KEY_APP_LASTTAB, "playlist"));
    } else {
        tabHost.setCurrentTabByTag(app.sp.getString(AppPreferenceActivity.KEY_APP_LASTTAB, "nowplaying"));
    }
}
+1  A: 

Create new Intents for each tab. Right now, you are setting all three tabs to a single Intent object.

Or, don't use Intents for tabs, but use Views instead.

CommonsWare
That fixed it. I'm curious as to why the first two tabs were working though...
Dianoga