My application have something like this:
TabActivity
Tab 1 (ActivityGroup)
Activity > Activity > MapActivity
Tab 2 (ActivityGroup)
MapActivity
The problem is that in the Tab 2 MapActivity the options menu does not appear, even displays an error. But in the first MapActivity works perfectly. I put a breakpoint inside the method onCreateOptionsMenu but even entered it.
I used this tutorial for make my application based in TabHost.
Could anyone help me to know why in one works and the other not?
Thanks in advance.
UPDATE
About version:
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="13" />
First MapActivity class:
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 0, 1, "Nearest");
menu.add(0, 1, 1, "Directions");
return true;
}
Second MapActivity class:
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 0, 1, "Nearest");
menu.add(0, 1, 1, "Region");
return true;
}
Basically a
TabHostonly has one options menu.I haven’t tested it, but my guess would be that it’s just using the first activity that returns true from
onCreateOptionsMenu. If you want a different options menu for each tab, you’ll have to do several things:1) Subclass
TabHostand overrideonCreateOptionsMenuandonPrepareOptionsMenu.2) When the tab changes (can’t remember how you listen for this event, google it), call
invalidateOptionsMenu, which will force a call toonPrepareOptionsMenu.3) In
onPrepareOptionsMenu, remember to callmenu.clear(), and then do the normal menu inflation stuff that you do inonCreateOptionsMenuto create your tab specific options menu.