What is the equivalent of requireActivity().invalidateOptionsMenu() in a fragment when using the new MenuProvider API?
When I get some new information at runtime, I need to refresh the menu in my fragment.
class MyFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
//... Rest of code not shown
requireActivity.addMenuProvider(myMenuProvider, viewLifecycleOwner, Lifecycle.State.RESUMED)
}
}
// ... Rest of code not shown
fun onDataChanged() {
//.. How do I refresh my menu using the `myMenuProvider` or the `MenuHost`?
}
}
The
MenuHostAPI that you are using to calladdMenuProviderhas another method:invalidateMenu():So you'd call
requireActivity().invalidateMenu().