I have created a custom tabbar in my application (using TabHost
and TabWidget
). However in my TabActivity
I want to invoke a method of the Activity
that is currently selected.
Here is a sample of how I initialize the tab bar:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabbar);
TabHost tabHost = getTabHost();
Intent content;
Button tabView;
TabSpec tab;
content = new Intent(this, Test1.class);
tabView = new Button(getApplicationContext());
tabView.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_tableft_selector));
tabView.setText("Test1");
tabView.setTypeface(font);
tabView.setTextColor(Color.WHITE);
tabView.setPadding(0, 2, 0, 0);
tab = tabHost.newTabSpec("test1").setIndicator(tabView).setContent(content);
tabHost.addTab(tab);
...
}
My problem is that in my TabActivity
and in all 3 tabs I want to receive LocationUpdates, but I need to do some validation before delivering the location updates to the tab's Activity
.
What I wanted to do is receive location updates in my TabActivity
, do the processing and then invoke some method in the current tab Activity
, however I can't access it from the tabHost. Is there a way to do this?
if they are all activities then you can use the ActivityGroup stuff since TabActivity extends ActivityGroup. You will need to define a location interface or something that all your activities implement to avoid crashes, or do checks. Also if your not too far along yet you should consider using the compatibility library and using fragments, as tabactivity and activitygroup have been deprecated
LocalActivityManager m = getLocalActivityManager();
((LocationInterface)m.getCurrentActivity()).sendLocation();