- Create one variable to check if the preferences fragment is not visible (isPrefsHiddden).
- Make this change to onPrepareOptionsMenu to hide the options menu if the preferences fragment is displayed (isPrefsHidden==false).
@Override
public boolean onPrepareOptionsMenu (Menu menu) {
//hide options menu if preference fragment is visible
return isPrefsHidden;
}
- When the preferences fragment is no longer visible, change the variable to true to activate the options menu again. You will have to call invalidateOptionsMenu() whenever you change the variable so that the GUI becomes properly updated.