views:

271

answers:

0

I have a TabActivity with four tabs (each is its own Activity). Each tab defines its own onCreateOptionsMenu (and in some cases, onPrepareOptionsMenu). When each tab is loaded, an AsyncTask is kicked off to retrieve the data needed to populate that tab's list.

If I switch between tabs very quickly (while they're still loading) and then press the menu button (while the current tab's AsyncApiTask is still running), I'm able to get the wrong options menu to appear.

For example, let's say FooActivity (tab 1) has an options menu with a "Refresh" item, and BarActivity (tab 2) has an options menu with a "View All" item. If I start the app (with tab 1 active), quickly switch to tab 2, and then hit menu, the "Refresh" item (rather than the expected "View All" item) will sometimes show.

Furthermore, while this weird behavior sometimes occurs just on the first menu press (and later presses show the right items), sometimes it gets "stuck", and the wrong items show up on every press until I switch tabs.

Any idea what could be going on? I haven't heard of this happening before, and haven't been able to find any good suggestions.