0

enter image description here

in v4.fragment, i set setHasOptionsMenu(true); and then in onCreateOptionsMenu i set inflater.inflate(R.menu.menu_fragment, menu);, everything is ok until i switch language.

when the app is running, and i press home-key, open setting, change locale language, select my running app from recently app list, the option menu in actionbar will increase duplicate menuitem, what's happen?

GeminiYellow
  • 1,016
  • 2
  • 12
  • 34
  • show activity and fragment source code – Dima Feb 19 '13 at 12:29
  • 1
    I probably know why . when i change the locale, the android will recall the onCreate method in the Activity which is showing, unless you set the manifest . in my activity, the fragment will be regenerate and attach to Activity,the old fragment in fragmentmanager and the newly fragment in the same Activity.So the activity have the duplicate menu item. – GeminiYellow Feb 20 '13 at 05:44

1 Answers1

1

Gemini, I know it is late and you most probably have the answer already. The easiest way to fix this issue is to just add menu.clear();

public void onPrepareOptionsMenu(Menu menu) {
  MenuInflater inflater = new MenuInflater(getActivity().getApplicationContext());

  menu.clear();

  super.onPrepareOptionsMenu(menu);
  inflater.inflate(R.menu.myMenu, menu);
}
SISLAM
  • 50
  • 5