(v4.0) onCreateOptionsMenu() not called in Fragment?

949 views
Skip to first unread message

jamesc

unread,
Jan 3, 2012, 8:37:29 AM1/3/12
to ActionBarSherlock
Hi

I've just integrated the 4.0 ABS code (using the rebuilt support lib).
I've a single FragmentActivity that 'manages' two Fragments.

When running on an ICS device:
- App starts
- FragmentActivity's onCreateOptionsMenu() is called
- Fragment 1's onCreateOptionsMenu() method is called.
- Fragment 2's onCreate() is called (and contains a call to
setHasOptionsMenu(true))
- Fragment 2's onCreateOptionsMenu() method is called.

All fine.

When running on a 2.3.x device, all is the same, save for the last
step:

- Fragment 2's onCreateOptionsMenu() method is not called.

This appears to be a regression on the previous behaviour (perhaps I'm
abusing the ordering, since I'm reliant upon that call).

I realise you, Jake, get a lot of these 'Menu bugs' (which aren't),
and I've combed the imports for correctness. Any ideas?

Much appreciated

James

jamesc

unread,
Jan 3, 2012, 11:09:39 AM1/3/12
to ActionBarSherlock
So it appears that this is the old (3.5) behaviour:

v4.Fragment.setHasOptionsMenu()
-> SupportActivity.invalidateOptionsMenu()
-> dispatchCreateOptionsMenu()

The new behaviour is (I'm only looking at the r6 source, since I can't
see the rebuilt support package):

v4.Fragment.setHasOptionsMenu()
->FragmentActivity.supportInvalidateOptionsMenu()
-> has some hack on <3.x platforms

Jake, is the rebuilt support package source up somewhere? Or is the
above enough info? Or, have I totally missed something?

Cheers

James

Jake Wharton

unread,
Jan 3, 2012, 11:12:14 AM1/3/12
to actionba...@googlegroups.com
The source is at http://abs.io/b/4.0-wip under plugins/compat-lib/. However, I think that just clicked in my head as I'm pretty sure I didn't take into account that setHasOptionsMenu should trigger invalidation. I will look at this at lunch.

---
Jake Wharton
http://about.me/jakewharton

jamesc

unread,
Jan 4, 2012, 6:12:12 AM1/4/12
to ActionBarSherlock
Just to let you know, the fix is good (v4.0#4).

Cheers

James

On Jan 3, 4:12 pm, Jake Wharton <jakewhar...@gmail.com> wrote:
> The source is athttp://abs.io/b/4.0-wipunder plugins/compat-lib/.
> However, I think that just clicked in my head as I'm pretty sure I didn't
> take into account that setHasOptionsMenu should trigger invalidation. I
> will look at this at lunch.
>
> ---
> Jake Whartonhttp://about.me/jakewharton
Reply all
Reply to author
Forward
0 new messages