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.

Always call @AfterExtras methods #1528

@m-radzikowski

Description

@m-radzikowski

Hey,
I've an Activity with one extra:

    @Extra
    protected Long id;

There are two use cases for this activity:

  • pass id in extra to edit existing entity,
  • don't pass any extra to open activity for new entity creation.

So I've had method:

    @AfterExtras
    protected void setupEntity() {
        if (id != null) {
            entity = loadEntityById(id);
        } else { // create new entity with default data
            entity = new Entity();
            // some more initialization of entity
        }
    }

But code generated by AA is:

    private void injectExtras_() {
        Bundle extras_ = getIntent().getExtras();
        if (extras_!= null) {
            if (extras_.containsKey(ID_EXTRA)) {
                id = ((Long) extras_.getSerializable(ID_EXTRA));
            }
            setupEntity();
        }
    }

So my setupEntity() method is not called if in result I'm unable to check if this single extra was passed or not in AA style and perform actions based on this. So I have two propositions:

  • [EASY?] change generated code to:
    private void injectExtras_() {
        Bundle extras_ = getIntent().getExtras();
        if (extras_!= null) {
            if (extras_.containsKey(ID_EXTRA)) {
                id = ((Long) extras_.getSerializable(ID_EXTRA));
            }
        }
        setupEntity();
    }
  • [HARD] add required extras to intent builder,
  • tell me what is better way to handle this without boilerplate code, AA style?

Tested on AA 3.3.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions