3
我正在嘗試使用Tabhost,我有2個選項卡,每個加載一個Activity,每個Activity都有一個aSync方法來解析一些數據。如果我在創建Tabmenu Activity時做了setCurrentTab(0)
一切正常,但是如果我嘗試在第二個選項卡(setCurrentTab(1)
)上啓動應用程序,它會嘗試加載第一個選項卡,並執行第一個選項卡的aSync方法並崩潰,因爲某些數據缺乏工作方法,根本不應該被稱爲。第一個標籤總是叫
這裏的TabMenu.Activity:
public class TabMenu extends TabActivity {
TabHost tabHost = null;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
setResult(resultCode);
this.finish();
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
Intent intentToGet = getIntent();
tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
TabHost.TabSpec spec2;
Intent intent2;
intent = new Intent().setClass(this, HoursActivity.class);
intent.putExtra("student", intentToGet.getStringExtra("student"));
intent.putExtra("pass", intentToGet.getStringExtra("pass"));
intent.putExtra("un", intentToGet.getStringExtra("un"));
spec = tabHost
.newTabSpec("hours")
.setIndicator("Hours")
.setContent(intent);
tabHost.addTab(spec);
intent2 = new Intent().setClass(this, NotesActivity.class);
intent2.putExtra("student", intentToGet.getStringExtra("student"));
intent2.putExtra("pass", intentToGet.getStringExtra("pass"));
intent2.putExtra("un", intentToGet.getStringExtra("un"));
spec2 = tabHost
.newTabSpec("notes")
.setIndicator("Notes")
.setContent(intent2);
tabHost.addTab(spec2);
tabHost.setCurrentTab(1);
}
}
任何想法?