Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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

Copy link
Copy link
@m-radzikowski

Description

@m-radzikowski
Issue body actions

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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.