TabHost在页面切换的时候因为有缓存机制存在,所以在页面切换的时候,只有第一次调用显示界面才会执行onCreate,其他情况下不会执行。
但是可以通过一个”错误”的方法来去掉这个缓存机制,使每次切换页面都调用onCreate
正常情况下,加载TabHost的页面如下,缓存作用:
tabHost.addTab(tabHost.newTabSpec("aa1")
.setContent(new Intent(RadioGroupSnailExtendTabActivity.this,Include1TabActivity.class))
.setIndicator("基本信息",getResources().getDrawable(R.drawable.ic_launcher))
);
tabHost.addTab(tabHost.newTabSpec("bb")
.setContent(new Intent(RadioGroupSnailExtendTabActivity.this,Include2TabActivity.class))
.setIndicator("更多信息",getResources().getDrawable(R.drawable.ic_launcher))
);
tabHost.addTab(tabHost.newTabSpec("cc")
.setContent(new Intent(RadioGroupSnailExtendTabActivity.this,Include3TabActivity.class))
.setIndicator("附加",getResources().getDrawable(R.drawable.ic_launcher))
);
使缓存失效的方法:
tabHost.addTab(tabHost.newTabSpec("aa")
.setContent(new Intent(RadioGroupSnailExtendTabActivity.this,Include1TabActivity.class))
.setIndicator("基本信息",getResources().getDrawable(R.drawable.ic_launcher))
);
tabHost.addTab(tabHost.newTabSpec("aa")
.setContent(new Intent(RadioGroupSnailExtendTabActivity.this,Include2TabActivity.class))
.setIndicator("更多信息",getResources().getDrawable(R.drawable.ic_launcher))
);
tabHost.addTab(tabHost.newTabSpec("aa")
.setContent(new Intent(RadioGroupSnailExtendTabActivity.this,Include3TabActivity.class))
.setIndicator("附加",getResources().getDrawable(R.drawable.ic_launcher))
即在newTabSpec的时候将其tag全部设置为一样