Search code examples
javaandroidandroid-annotations

Android Annotations EActivity isn't getting one of the Extras


I'm using Android Annotations on my NavControllerActivity which has two @Extras. One extra is a parcelable custom class, BaseEntity and the other is a java.lang.Class object (which is Serializable). However, when my Activity starts up, I'm only getting the entity, I'm not getting the rootFragmentClass.

@EActivity
public class NavControllerActivity extends AppCompatActivity {

    @Extra
    BaseEntity entity;

    @Extra
    Class rootFragmentClass;

    // ....

    @AfterExtras
    public void setupViews() {

        Log.d("Nav", "rootFragmentClass: "+this.rootFragmentClass);
        Log.d("Nav", "entity: "+this.entity);


    }

}

I launch the activity like this:

NavControllerActivity_.intent(this)
    .rootFragmentClass(EditAnimalFragment_.class)
    .entity(entity)
    .start();

When setupViews() is executed, my entity has the correct value, but the rootFragmentClass is null.

Am I doing something wrong?


Solution

  • I made some code changes which fixed the problem and here's my assumption about what was really going wrong.

    The error I made was in my Parcel in/out code. I was writing 20 fields to the Parcel, but when reading from the Parcel I was only reading 15 fields. Making sure my in-code matched my out-code made the problem go away.

    I wasn't getting any exceptions when I first encountered this, but when I was doing more investigation as to what was going wrong (Android Annotations, Parcelable object as Extra, producing IllegalArgumentException: is not a constant in android.text.Layout$Alignment) I finally did get an exception.

    That eventually lead me to realizing that my in-code didn't match my out-code.

    I think what was happening is that since there was still data to unparcel that it was screwing up another item that needed to get unpacked and throwing an exception that seemed unrelated.