OnCreate() of first tab gets called even when second tab is defined as CurrentTab <p>I have an activity on which I have a <code>TabHost</code> and a <code>TabWidget</code> like this:</p> <pre><code>&lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_gravity="bottom" 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" android:padding="5dp"&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0dip" android:padding="5dp" android:layout_weight="1" /&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; &lt;/TabHost&gt; </code></pre> <p>I use the following code to add three tabs and their respective activities to the <code>TabHost</code>:</p> <pre><code>private void CreateTabs() { TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab String strJson = Intent.GetStringExtra (Constants.JSON_RESPONSE); // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent (this, typeof (FirstActivity)); if (strJson != null) { intent.PutExtra (Constants.JSON_RESPONSE, strJson); } intent.AddFlags (ActivityFlags.NewTask); // Initialize a TabSpec for each tab and add it to the TabHost spec = TabHost.NewTabSpec ("first"); spec.SetIndicator ("First", Resources.GetDrawable (Resource.Drawable.FirstIcon)); spec.SetContent (intent); TabHost.AddTab (spec); // Do the same for second tab intent = new Intent (this, typeof (SecondActivity)); if (strJson != null) { intent.PutExtra (Constants.JSON_RESPONSE, strJson); } intent.AddFlags (ActivityFlags.NewTask); spec = TabHost.NewTabSpec ("second"); spec.SetIndicator ("Second", Resources.GetDrawable (Resource.Drawable.SecondIcon)); spec.SetContent (intent); TabHost.AddTab (spec); // Do the same for third tab intent = new Intent (this, typeof (ThirdActivity)); if (strJson != null) { intent.PutExtra (Constants.JSON_RESPONSE, strJson); } intent.AddFlags (ActivityFlags.NewTask); spec = TabHost.NewTabSpec ("third"); spec.SetIndicator ("Third", Resources.GetDrawable (Resource.Drawable.third_icon)); spec.SetContent (intent); TabHost.AddTab (spec); //Set the tab you want to show TabHost.CurrentTab = 1; } </code></pre> <p>As you can see that at the last line I am making the second tab to be shown when I open this tabbed activity and that is what it does but actually it first calls the <code>OnCreate</code> of <code>FirstActivity</code> and then calls <code>OnCreate</code> of <code>SecondActivity</code> before showing the <code>SecondActivity</code>. (The <code>OnCreate</code> of <code>ThirdActivity</code> is only called when I tap on the third tab to actually see that activity, which is absolutely fine).</p> <p>I want that the <code>OnCreate</code> of <code>FirstActivity</code> to be only called when I tap on the first tab because:</p> <ol> <li>the app does some work that is not required at that instance and hence using unnecessary resources.</li> <li>More importantly, my <code>FirstActivity</code> gets the user's current location and if I get it before the user actually navigates to the required screen then it may not be correct if the user has already changed his location.</li> </ol> <p>Please let me know how to achieve that?</p>