I'am using a TabActivity where I add TabSpec's with Intent content
that starts child activities. I want to "remember" which tab is
active, so I store the "tag" in a SharedPreferences.

When restoring in onCreate, I use tabHost.setCurrentTab. This it work.
But looking at the log, the TabActivity also creates the first tabs
activity before the setCurrentTab call. I've also tried setDefaultTab,
it does nothing.

Example code:

public class MyActivity extends TabActivity {
  public void onCreate (Bundle state) {
    super.onCreate(state);
    setContentView(R.layout.main);
    TabHost tabHost = getTabHost();
    tabHost.addTab(tabHost.newTabSpec("tab1")
      .setIndicator("Tab1").setContent(new Intent(this,
Tab1Activity.class)));
    tabHost.addTab(tabHost.newTabSpec("tab2")
      .setIndicator("Tab2").setContent(new Intent(this,
Tab2Activity.class)));
    setDefaultTab("tab2"); // does nothing?
    tabHost.setCurrentTabByTag("tab2"); // too late, Tab1Activity
already created!
  }
}

Still Tab1Activity.onCreate is called, wasting memory.

Hmm. Looking at TabHost source it seems setCurrentTab is called in the
first addTab, always focusing on the first added TabSpec.  Bug?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to