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.

@InstanceState on custom view is misleading #1959

@yolapop

Description

@yolapop

AndroidAnnotations version: 4.2.0

Android compile SDK version: 25

Hi, i found an odd API here. When I found AA has supported @InstanceState, I was happy that I don't have to write custom parcelable again. But, it doesn't work like what I expected.

As you can see here I'm saving view states (background, checked state) on @InstanceState.

Annotated code:

@InstanceState protected boolean checked = false;
@InstanceState protected String label;
@InstanceState protected boolean selectableMode = false;
@InstanceState protected int normalBackgroundColor, selectedBackgroundColor;

But after onRestoreInstanceState is called, there is no way to set the restored states back to the view.

Generated code:

@Override
public void onRestoreInstanceState(Parcelable state) {
    Bundle bundle_ = ((Bundle) state);
    Parcelable instanceState = bundle_.getParcelable(INSTANCE_STATE_KEY);
    super.onRestoreInstanceState(instanceState);
    checked = bundle_.getBoolean("checked");
    label = bundle_.getString("label");
    selectableMode = bundle_.getBoolean("selectableMode");
    normalBackgroundColor = bundle_.getInt("normalBackgroundColor");
    selectedBackgroundColor = bundle_.getInt("selectedBackgroundColor");
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions