Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification: onCreateOptionMenu() called ones but onPrepareOptionMenu() every time #33

Open
johnnyfivedev opened this issue May 27, 2019 · 3 comments

Comments

@johnnyfivedev
Copy link

Fact:
onCreateOptionMenu() called ones but onPrepareOptionMenu() every time.

Proof:
onCreateOptionMenu() is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see onPrepareOptionsMenu(Menu).

onPrepareOptionMenu() Prepare the Screen's standard options menu to be displayed. This is called right before the menu is shown, every time it is shown

Problem:
Block diagram shows that every time onResume() called both onCreateOptionMenu() and onPrepareOptionMenu() are called. Which is not true.

Solutions:
"Called once, the first time the options menu is displayed or if menu invalidated" comment need to be added there or condition (diamond-like) block with text "first menu display or invalidated" and "yes" and "no" branches

@oradkovsky
Copy link

"called once" - under which conditions? The above is true for activity but not for fragments. If you have backstack, every backing (assuming backstack is single container based) will trigger creation of view and the menu (that is, among others onCreateOptionsMenu, onPrepareOptionsMenu will be called). If backstack is multi container based (I don't even know if it's officially supported by google), I think onCreateOptionsMenu/onPrepareOptionsMenu will even be called for fragment that's in backstack but in different container then the upper fragment.

@johnnyfivedev
Copy link
Author

johnnyfivedev commented May 28, 2019

The above is true for activity but not for fragments

If the above is true only for activity, then changes should be made only for activity diagram.

@johnnyfivedev
Copy link
Author

@xxv any comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants