Done by calling setMenuVisibility(true);
in onResume
of my Fragment class.
Fragment onCreateOptionsMenu not getting called on orientation change
-
31-05-2022 - |
Question
I have a activity having multiple fragments in viewpager. When I open option menu it adds menu items from particular fragment to option menu. I am using android 4.2
and has android:configChanges="orientation"
I have not added screensize
due to which activity will be created on orientation change which I want.
When I open option menu all menus including fragment menu items are shown. But if I rotate device while option menus is showing only option menu items of activity are shown. I checked it is because fragment onCreateOptionsMenu
is not called when I change orientation. How can I add fragment option menu items to already shown option menu while changing orientation .
Solution 2
OTHER TIPS
Edit: With Android O, supportInvalidateOptionsMenu
is deprecated. Use directly invalidateOptionsMenu()
That's correct. Android
will fire onConfigurationChanged
override it and call supportInvalidateOptionsMenu();
I fixed it with a call to:
setHasOptionsMenu(true)
In the onCreateView method of the Fragment