I have 4 tabs in a page view when i click first time on tab it executes it oncreate()
method of corresponding tab and when i go to other tab on same page and again
Tabs that contain activities are implemented by means of ActivityGroup. When someone changes a tab, corresponding activity is created only if necessary. When you move to any tab for the second time, the activity is already existing and only its window is shown. You should use instead:
TabHost.setOnTabChangedListener(TabHost.OnTabChangeListener l)
TabActivity with separate activities as a content are a little bit tricky so maybe you should consider using Views instead. If not you can use the following code to access all activities from each other:
get instances of content activities from TabActivity:
TabActivity.getLocalActivityManager().getActivity(String name)
where name is given in newTabSpec() method.
get instance of TabActivity from content activities:
FirstTab.getParent()
Using these method you can create communication between all activities (using proper casting). For example:
public void onTabChanged(String label) {
if(label.equals("Activity2")) {
SecondActivity sa = (SecondActivity) getLocalActivityManager().getActivity(label);
sa.modifySomething();
}
}
If you want to change activities under tabs you should use:
tabHost.clearAllTabs ()
and create all TabSpecs once again.
In the android oncreate() lifecycle called once in life of the activity (like constructor), as you press again that time the activity is alive and in memory so it will not call onCreate again.
so you have to implement
TabHost.setOnTabChangedListener(TabHost.OnTabChangeListener l).