Status Update
Comments
ow...@google.com <ow...@google.com>
al...@google.com <al...@google.com>
il...@google.com <il...@google.com>
jb...@google.com <jb...@google.com> #2
I am not sure I understand what you are asking for here.
The contract of onPrepareMenu
in MenuProvider
is:
"Called by the MenuHost right before the Menu is shown. This should be called when the menu has been dynamically updated."
If you were using Toolbar
prior to the MenuHost
integration, this should be a no-op for you. And if you are now switching to Toolbar, the onPrepareMenu()
call should be in the proper place.
But the contract is not being violated.
If you are seeing some unexpected behavior, please provide a sample app that reproduces the error that you are observing.
to...@yahoo.com <to...@yahoo.com> #3
reuploading my previous sample app.
It's fairly simple.
Call order with AppCompat 1.5.0-alpha01:
- onCreateMenu
- onPrepareMenu
- user opens menu
- menu is displayed
According to the contract:
"Called by the MenuHost right before the Menu is shown.
it should be:
- onCreateMenu
- user opens menu
- onPrepareMenu
- menu is displayed
build and run the sample. It has examples for both activity and fragment. Follow the print out's in the log.
ap...@google.com <ap...@google.com> #4
Branch: androidx-main
commit 723f2ef10ea1de61e94de16b917cc6e939bfc211
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Aug 02 17:05:42 2022
Fix Toolbar onPrepareMenu timing with MenuHost
Instead of unconditionally calling onPrepareMenu() when Toolbar executes
onCreateMenu(), it should wait until the menu is about to be shown to
make the call.
This will ensure that Toolbar properly fulfills the MenuHost contract.
RelNote: "Toolbar will now call `onPrepareMenu()` before the menu is shown
instead of unconditionally when the menu is created."
Test: modified the ToolbarMenuHostTest
Bug: 232206677
Change-Id: I2a58df0064c08b9ae87962a41d87e7bc60073df0
M appcompat/appcompat/src/main/java/androidx/appcompat/widget/Toolbar.java
M appcompat/appcompat/src/androidTest/java/androidx/appcompat/widget/ToolbarMenuHostTest.kt
jb...@google.com <jb...@google.com> #5
This has been fixed internally and will be available in the AppCompat 1.6.0-beta01
release.
Description
Please see https://issuetracker.google.com/227376894
and the earlier related issue(s)
This needs to be re-opened as the fix mentioned in
is itself introducing a new bug; please the source code for that fix.
Please may I remind you about the contract for onPrepareMenu: called when the menu is first shown
But in your code, you now simply call onPrepareMenu during the onCreateMenu phase.
I realise that Toolbar did/does not implement onPrepareMenu properly up to now, but it never promised to do, so that was ok up to now.
However, if you're adding support for MenuProvider (thank you!) then it has to be implemented such that it's contract is fulfilled. Right now, the contract of the MenuProvider is broken in Toolbar.