Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

@OptionsItem doesn't allow subclasses to override menu item handling  #1067

@jacobtabak

Description

@jacobtabak

The generated code for onOptionsItemSelected calls your superclass's onOptionsItemSelected() before the subclass, removing your ability to override functionality in the subclass. I believe the only workaround is to override onOptionsItemSelected() in your activity (rather than use @OptionsItem annotation) because I don't think there's a way to achieve the same goal using AndroidAnnotations.

Here's the generated code. My base activity class handles android.R.id.home.

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        boolean handled = super.onOptionsItemSelected(item);
        if (handled) {
            return true;
        }
        int itemId_ = item.getItemId();
        if (itemId_ == android.R.id.home) {
            onHomeTapped();
            return true;
        }
        return false;
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions