Issue
In my Activity which is a Support v7 ActionBarActivity, I have menu and a navigation drawer.
When ever the navigation drawer is open I want to hide the menu items.
I hide them in the onPrepareOptionsMenu().
As stated in the documentation from android, in order to trigger an onPrepareOptionsMenu() you need to call supportInvalidateOptionsMenu().
I'm doing just that. But after I call supportInvalidateOptionsMenu(), the onCreateOptionsMenu() is called and than the onPrepareOptionsMenu().
As I understood the onCreateOptionsMenu() should be called only once at the beginning of the Activity.
Am I missing something?
Solution
The correct cycle is:
- Calling
supportInvalidateOptionsMenu()leads to the menu getting recreated, i.e.onCreateOptionsMenu()gets called. - Whenever
onCreateOptionsMenu()is called,onPrepareOptionsMenu()is called to prepare the menu.
So calling supportInvalidateOptionsMenu() will always lead to onCreateOptionsMenu() getting called. Hope this helps clear the confusion.
Answered By - Yash Sampat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.