Search code examples
android-tabhost

2 activity contents are mixed when new activity is started on tabhost


I am using below code to start new activity on each tab. But now activity is opened on top of previous activity i.e. content of both the activities previous and new are mixed. How to avoid this ? Want to show only new activity. In this case Mainactivity.class and pushups.class contents are mixed.

    TabHost tabHost;
    TabHost host = (TabHost)findViewById(R.id.tabHost);
    host.setup(this.getLocalActivityManager());

    //Tab 1
    TabHost.TabSpec spec = host.newTabSpec("Push-ups");
    spec.setIndicator("Push-ups");
    spec.setContent(new Intent(this, Pushups.class));
    host.addTab(spec);

Solution

  • Got the answer!

    Was trying to add tabs on already developed page which had some text on it. As a solution, created a blank activity, added the tabhost code and then for each tab used above code to open separate activities.