I'm having a problem communicating between activities that are managed by a TabHost. Especially the problem is this:
- There is a main class that extends TabActivity; in it is a TabHost with 4 screens;
The 4 screens are 4 different activities, managed by TabHost like this :
private void setupScreen1{ intent.setClass(this, Class1.class); TabHost.TabSpec spec = tabHost.newTabSpec("a1") .setIndicator(getString(R.string.week_view), getResources().getDrawable(R.drawable.icon1)) .setContent(intent); tabHost.addTab(spec); }
- From Screen1 I need to change the TabHost's currentTab to Screen2 and send some data to Screen2. To to this I have 2 BroadcastReceivers.
--> one to sent an intent to the main class to switch the tab (in this onReceive() I just do a :
setCurrentTab(intent.getIntExtra(DATA, -1));
--> the other one to sent data to Screen2 : Scree开发者_开发知识库n2 uses this data inonCreate()
as a title; also in Screen2.onCreate() there is the BroadcastReveiver that listenes for this data to be used as title
The problem is : the first time the TabHost switches to the Screen2 the data is not sent because the BroadcastReciver has not been registed yet (since Screen2.onCreate() is just called). After this it seems to work ok every time.
Does anyone know how to work around this problem ?
精彩评论