android first tab intent oncreate always called regardless we set tab2 as default tab

Discussion in 'Application Development' started by faisalloe, Mar 3, 2010.

  1. faisalloe

    faisalloe Member
    15

    Jan 21, 2010
    17
    0
    15
    Following is the example of tabs with intent data.

    While debugging i found that always when first tab we add in tab host in our case following tab

    Code (Text):
    1. tabHost.addTab(tabHost.newTabSpec("tab1")
    2.                     .setIndicator("list")
    3.                     .setContent(new Intent(this, List1.class)));
    oncreate method of "List1" intent get called regardless it is our current tab or not even if if i define tab2 as a current tab how to fix this ?

    Code (Text):
    1. public class Tabs3 extends TabActivity {
    2.  
    3.     @Override
    4.     protected void onCreate(Bundle savedInstanceState) {
    5.         super.onCreate(savedInstanceState);
    6.  
    7.         final TabHost tabHost = getTabHost();
    8.  
    9.         tabHost.addTab(tabHost.newTabSpec("tab1")
    10.                 .setIndicator("list")
    11.                 .setContent(new Intent(this, List1.class)));
    12.  
    13.         tabHost.addTab(tabHost.newTabSpec("tab2")
    14.                 .setIndicator("photo list")
    15.                 .setContent(new Intent(this, List8.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
    16.  
    17.         // This tab sets the intent flag so that it is recreated each time
    18.         // the tab is clicked.
    19.         tabHost.addTab(tabHost.newTabSpec("tab3")
    20.                 .setIndicator("destroy")
    21.                 .setContent(new Intent(this, Controls2.class)
    22.                         .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
    23.     }
    24. }
     

    Advertisement

Share This Page

Loading...