Options menu doesn't appear any more

86 views Asked by At

I'm facing with strange problem, my old Android project suddenly is not showing menu options.

Code for menu:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:id="@+id/menu_preferences"
          android:icon="@drawable/icon_preferences"
          android:showAsAction="always"
          android:visible="true"
          android:title="Preferences" />

    <item android:id="@+id/menu_datatransfer"
          android:icon="@drawable/transfer"
          android:showAsAction="always"
          android:visible="true"
          android:title="Data transfer" />
</menu>

And this is for creating menu:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.

    MenuInflater menuInflater = getMenuInflater();      
    menuInflater.inflate(R.layout.menu, menu);
    return true;

}

The strange things is that if I put breakpoint on those lines debuger doesn't stop on them. Seems that somehow onCreateOptionsMenu is not called while application is starting. How is this possible?

SDK version is 17.

2

There are 2 answers

0
Josef On

I've found that menu disappeard when I changed minSDK and targetSDK. The previous version was 9. But one another thing was when i leave minSDK at 9 and target 13; my application works with web service and after changing target to higher version application was unable to communicate with service even in manifest internet premission is added.

0
Mohammad Rababah On

You must add onOptionsItemSelected like below:

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.YourID:
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }