title: Implement options menu in Fragment Activity
body: <p>I have two fragment activities and one fragment. Here's how the app logic looks like:</p>
  
  <pre><code>FragmentActivity A ==&gt; Fragment B ==&gt; FragmentActivity C.
  </code></pre>
  
  <p>FragmentActivity A is the parent activity of fragment B and has an options menu that shows correctly.Fragment B contains a listview. When a list item is clicked on fragment B,its details are displayed in FragmentActivity C.Now i want to display an options menu inside C in the actionBar.However, the menu is only displayed after the menu button is clicked.I want it as an actionbar action.</p>
  
  <p>Here is the code for Activity C:</p>
  
  <pre><code>public class LatestDetailsFragment extends FragmentActivity implements
      OnItemClickListener {
  
  public LatestDetailsFragment() {
      photoImages = new ImageItem();
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.fragment_latestdetails);
  
      gallery.setOnItemClickListener(this);
      // setHasOptionsMenu(true);
  }
  
  
      @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.details_fragment_menu, menu);
  
      return super.onCreateOptionsMenu(menu);
  }
  
  /* *
   * Called when invalidateOptionsMenu() is triggered
   */
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
      return super.onPrepareOptionsMenu(menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle item selection
      switch (item.getItemId()) {
      case R.id.contact:
          ContactOwnerFragment contactFragment = new ContactOwnerFragment();
          Bundle bundle = new Bundle();
          bundle.putString(KEY_PHONE, phone);
          contactFragment.setArguments(bundle);
          contactFragment.show(getSupportFragmentManager(), "contact");
          return true;
      default:
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>And the menu:</p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  tools:context="be.hcpl.android.example.MainActivity" &gt;
  
  &lt;item
      android:id="@+id/contact"
      android:icon="@drawable/ic_action_call"
      android:orderInCategory="100"
      android:title="@string/contact"
      app:showAsAction="ifRoom|withText"&gt;
  &lt;/item&gt;
  </code></pre>
  
  <p></p>
  
  <p>I cannot use <code>setHasOptionsMenu(true);</code> on the activity because it raises an error,I don't know why. I want to display an icon on the actionbar.</p>