I’m trying to work with Tabhost, I have 2 tabs, each one loads one Activity, each Activity has an aSync method to parse some data. If I do setCurrentTab(0) when creating the Tabmenu Activity everything works fine, but if I try to start the app on the second tab(setCurrentTab(1)) it tries to load the first tab, and does the aSync method of the first tab and crashes because some data is lacking for method to work, which wasn’t supposed to be called at all.
Here’s the 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);
}
}
Any ideas?
In the past I have had to do something similar and solved it by doing the following:
So when you click on the tab, the onResume will be called and the Activity can do whatever set up is needed. There may be a problem with performance if the load function is slow to perform, in which case you will need to modify it slightly to not wait until the onResume to load (keeping it async). But that should at least get you started off.