Option menu of the previous fragment is preserved after switching fragment

482 views Asked by At

I have an activity with a navigation drawer and fragments (Fragment Lvl 1). One of these fragments contains nested children(Fragment Lvl 2) with a viewpager adapter. When I add an option menu to the nested child (Lvl 2) it stills appearing on the newely displayed fragment when I'm switching between fragement (Lvl 1) from the navigation drawer.

It's seems like the Fragment wich containing the view pager is not telling the activity that is has been hidden or whatever.

2

There are 2 answers

1
user1758939 On

Finally I solved that by calling Menu.clear() on onDetach() in the nested fragment (Lvl2).

But it will be nice , if someone could provide me a better solution.

0
mixel On

I had the similar issue because I was providing getFragmentManager() to FragmentPagerAdapter constructor instead of getChildFragmentManager().