Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
Component used: Fragment / androidx.activity.ComponentActivity
Version used:
androidx.fragment:fragment
1.5.x (anything older than 1.4.x) Because from 1.5.x library is using dependencies ofandroidx.activity:activity:1.4.0
Devices/Android versions reproduced on: Pixel 3 Android 11, Pixel 5 Android 12
Description: From activity 1.4.0 there is a MenuHost mechanism implemented in the
androidx.activity.ComponentActivity
So there are methods likeremoveMenuProvider
andaddMenuProvider
which are added by specificFragmentManager
classes. If we add a new fragment, and later we will remove it, it will automatically callMenuHostHelper.mOnInvalidateMenuCallback.run()
which under the hood is theComponentActivity.invalidateMenu
which callsinvalidateOptionsMenu
at the endLets imagine situation that one of the Fragments is inflating the menu items in which one of the items is the SearchView. Later while typing in the search view, and base on the query we want to present results, so we are adding and removing new fragments. While removing the fragment, by mechanism described above,
invalidateOptionsMenu
is called, which will clear all the items from the menu, while clearing it will collapse the search view, and the search view will be recreated collapsed without querySteps to reproduce
androidx.appcompat.widget.SearchView
SearchView.OnQueryTextListener
.onQueryTextChange
)invalidateMenu
is called so internallyinvalidateOptionsMenu
is called, later internallyToolbarActionBar.populateOptionsMenu
is called which is clearing all menu items so the whole SearchView is destroted.Before this was not the case, and the SearchView was not collapsed/destroyed, because the whole menu was not invalidated/cleared.
What can we do about that, because right now, if for every new letter in the query we want to show results by adding/removing fragments (i.e. in the ViewPager) SearchView is being cleared and destroyed.
This might be connected to:
issue https://issuetracker.google.com/issues/244854449
and issue https://issuetracker.google.com/issues/244336571