Status Update
Comments
il...@google.com <il...@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.
al...@google.com <al...@google.com>
ap...@google.com <ap...@google.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.
jb...@google.com <jb...@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
na...@google.com <na...@google.com> #5
This has been fixed internally and will be available in the AppCompat 1.6.0-beta01
release.
Description
Component used: Activity
Version used: 1.5.0-alpha05
Devices/Android versions reproduced on: Android 11
It appears that AppCompatActivity mistakenly doesn't set the ViewTreeOnBackPressedDispatcherOwner even though its superclass ComponentActivity does, looks like a copy-paste bug:
ComponentActivity:
AppCompatActivity: