load an activity when tab is selected
<p>I'm trying to load a "favourites" listview when I select the favourites tab in my app. All the tabs are displayed correctly, but when I go to select favourites the app crashes because of an IllegalStateException exception. </p>

<p>The java code is as follows: </p>

<pre><code>    public class tabs extends Activity{


        protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.tabmain);

            TabHost tabs=(TabHost)findViewById(R.id.tabhost);

            tabs.setup();

            TabHost.TabSpec spec=tabs.newTabSpec("tag1");    
            spec.setContent(R.id.tab1);
            spec.setIndicator("tab1");
            tabs.addTab(spec);

            spec=tabs.newTabSpec("tag2");
            spec.setContent(R.id.tab2);
            spec.setIndicator("tab2");
            tabs.addTab(spec);

            spec=tabs.newTabSpec("tag3");
            spec.setIndicator("Favourites", getResources().getDrawable(R.drawable.favourites_star));
            spec.setContent(new Intent(this,favourites.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
            tabs.addTab(spec);


        }


    }


    The xml file is as follows: 

    &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/tabhost"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
      &lt;LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"&gt;
        &lt;TabWidget android:id="@android:id/tabs"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
        /&gt;
        &lt;FrameLayout android:id="@android:id/tabcontent"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"&gt;

           &lt;LinearLayout 
          android:id="@+id/tab1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"/&gt;

           &lt;LinearLayout 
          android:id="@+id/tab2"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"/&gt;

          &lt;LinearLayout 
          android:id="@+id/tab3"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"/&gt;

        &lt;/FrameLayout&gt;
      &lt;/LinearLayout&gt;
    &lt;/TabHost&gt;


Stack Trace: 

Thread [&lt;3&gt; main] (Suspended (exception IllegalStateException)) 
    ViewRoot.handleMessage(Message) line: 1740  
    ViewRoot(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 123 
    ActivityThread.main(String[]) line: 4363    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 521  
    ZygoteInit$MethodAndArgsCaller.run() line: 860  
    ZygoteInit.main(String[]) line: 618 
    NativeStart.main(String[]) line: not available [native method]  
</code></pre>
