Question

My android application uses an overflow menu for settings, about, feedback etc.

the settings screen is provided by extending PreferenceFragment.

My min sdk is 14 my target sdk is 17.

when my users click on the settings option from my overflow menu and transition to my preferences screen the overflow icon is still visible, and the users can again click on it and select settings, which keeps letting them access "another" preference screen.

Whats the correct approach to stop this from occurring?

how should i be disabling the overflow menu when the preferences fragment is visible?
and re enabling it when the user returns from the preferences fragment?

Was it helpful?

Solution

  1. Create one variable to check if the preferences fragment is not visible (isPrefsHiddden).
  2. 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;
    }

  1. 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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top