以下は、インテント データを含むタブの例です。
デバッグ中に、最初のタブが常にタブホストに追加されることがわかりました。
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("list")
.setContent(new Intent(this, List1.class)));
「List1」インテントのoncreateメソッドは、現在のタブであるかどうかに関係なく呼び出されます.tab2を現在のタブとして定義しても、これを修正するにはどうすればよいですか?
public class Tabs3 extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("list")
.setContent(new Intent(this, List1.class)));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("photo list")
.setContent(new Intent(this, List8.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
// This tab sets the intent flag so that it is recreated each time
// the tab is clicked.
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("destroy")
.setContent(new Intent(this, Controls2.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
}
}