javaandroidandroid-activityoncreateoptionsmenu

I´m trying to call other activity with MenuItem


I`m trying to call other activity with onCreateOptionsMenu and onOptionsItemSelected, but i dont know is imposible to debug and it doesn´t do the action, i have

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.login_settings, menu);º
    //return super.onCreateOptionsMenu(menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getGroupId();
    if(id == R.id.contactMenu) {
            Intent intent = new Intent(this, ContactActivity.class);
            this.startActivity(intent);
            return super.onOptionsItemSelected(item);
    }

    return true;
}

And the MenuItem

 <group
        android:id="@+id/contactMenu"
        android:checkableBehavior="single">
            <item
                android:id="@+id/contactSettings"
                android:icon="@drawable/correo"
                android:title="@string/ContactUs_settings" />
    </group>

thank you so much...


Solution

  • Change just like below code and works fine.You must need to use ItemId for select menuItem

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId(); //you must use item id not group id
        if(id == R.id.contactSettings) {
                Intent intent = new Intent(this, ContactActivity.class);
                startActivity(intent);
        }
        return true;
    }