Question: I've met a serious problem. I want to add the MenuItem after the user successfully logged in.

At the beginning I use the following method to make it available.

The following code doesn't work now , I mentioned it as to illustrate my idea.

```
Private Menu mymenu;
 public boolean onCreateOptionsMenu(Menu menu) {

        // TODO Auto-generated method stub

        super.onCreateOptionsMenu(menu);
        mymenu=menu;
        return super.onCreateOptionsMenu(menu);
 } 

public void process(){

        MenuInflater inflater=this.getMenuInflater();
        inflater.inflate(R.menu.my_menu,mymenu);

}

```

It seems this idea worked as I remembered.But after doing something I couldn't remember , It doesn't work!

After the debug , I find it's because mymenu=null .

I guessed there is a way to set mymenu=menu 

Can anyone help?

Answer: 
The problem you could be having with that code is calling the super twice.

To do what you want, you could override onPrepareOptionMenu and set the visibility to hidden on all menu items you don't want until your state is such that you want to "add" it.

```
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem menuItem = menu.findItem(R.id.<id of menuitem>);
    menuItem.setVisible(<condition>);
    return true;
}

```

and just use standard code in onCreateOptionsMenu:

```
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.<id of menu with all items you'll need>, menu);
    return true;
}

```
There is a method, [onPrepareOptionsMenu(Menu menu)](http://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu%28android.view.Menu%29) method which you could override and dynamically change the menus.