0

I am trying to send a Parcelable object from one activity to another but when I try to get the object back from the Intent extras, I get:

Runtime Exception "Parcel android.os.Parcel@9a7cc8: Unmarshalling unknown type code 7274595"

Code:

Launching Activity

public class Activity1 {

    public static void start(Activity currrentActivity, V1Modal modal) {
        Intent auIntent = new Intent(currrentActivity, Activity1.class);
        if (modal != null) {
            auIntent.putExtra(MODAL_DATA_KEY, modal);
        }
        auIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        currrentActivity.startActivity(auIntent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
       requestWindowFeature(Window.FEATURE_NO_TITLE);
       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_useriq);
       if (getIntent().getExtras() != null) {

           getIntent().setExtrasClassLoader(V1Modal.class.getClassLoader());
           if (getIntent().getExtras().containsKey(MODAL_DATA_KEY)) {
                modal = (V1Modal) getIntent().getExtras().getParcelable(MODAL_DATA_KEY);
           }
       }
    }

V1Model Class

public class V1Modal implements Parcelable {
    public static final Parcelable.Creator<V1Modal> CREATOR = new Parcelable.Creator<V1Modal>() {
        @Override
        public V1Modal createFromParcel(Parcel source) {
            return new V1Modal(source);
        }

        @Override
        public V1Modal[] newArray(int size) {
            return new V1Modal[size];
        }
    };
    public String id;
    String name;
    public Node layout;

    private V1Modal() {
    }

    protected V1Modal(Parcel in) {
        this.id = in.readString();
        this.name = in.readString();
        this.layout = in.readParcelable(UINode.class.getClassLoader());
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.name);
        dest.writeParcelable(this.layout, flags);
    }
}

UiNode Class

public abstract class UINode implements Parcelable {
    protected UINode(Parcel in) {
        this.bgColor = new ArrayList<>();
        in.readList(this.bgColor, Integer.class.getClassLoader());
        if (this.bgColor.size() == 0) {
            this.bgColor = null;
        }
        this.borderColor = new ArrayList<>();
        in.readList(this.borderColor, Integer.class.getClassLoader());
        if (this.borderColor.size() == 0) {
            this.borderColor = null;
        }
        this.borderWidth = in.readInt();
        this.borderRadius = new ArrayList<>();
        in.readList(this.borderRadius, Integer.class.getClassLoader());
        if (this.borderRadius.size() == 0) {
            this.borderRadius = null;
        }

        this.id = in.readString();
        this.type = in.readString();
        this.l = in.readString();
        this.r = in.readString();
        this.t = in.readString();
        this.b = in.readString();
        shadowRadius = in.readInt();
        shadowDx = in.readInt();
        shadowDy = in.readInt();
        this.shadowColor = new ArrayList<>();
        in.readList(this.shadowColor, Integer.class.getClassLoader());
        if (this.shadowColor.size() == 0) {
            this.shadowColor = null;
        }
    }

     public void writeToParcel(Parcel dest, int flags) {
        dest.writeList(this.bgColor);
        dest.writeList(this.borderColor);
        dest.writeInt(this.borderWidth);
        dest.writeList(this.borderRadius);
        dest.writeString(this.id);
        dest.writeString(this.type);
        dest.writeString(this.l);
        dest.writeString(this.r);
        dest.writeString(this.t);
        dest.writeString(this.b);
        dest.writeInt(shadowRadius);
        dest.writeInt(shadowDx);
        dest.writeInt(shadowDy);
        dest.writeList(shadowColor);
    }
    public int describeContents() { return 0; }

Node Class

public class Node extends UINode {
    public static final Creator<Node> CREATOR = new Creator<Node>() {
      @Override
      public Node createFromParcel(Parcel source) {
        return new Node(source);
      }

      @Override
      public Node[] newArray(int size) {
        return new Node[size];
      }
   };

   protected Node(Parcel in) {
    super(in);
    this.children = in.readArray(UINode.class.getClassLoader());
   }

  @Override
  public int describeContents() {
    return 0;
  }

  @Override
  public void writeToParcel(Parcel dest, int flags) {
    super.writeToParcel(dest, flags);
    dest.writeArray(this.children);
  }
}

I am injecting the Activity1 from the Xposed, hook after Instrumentation.newActivity method.

PS: Previously I was having the ClassNotFoundException on getting the model from the Intent extras then I set the class loader when trying to get the extras from the Intent.

sharonooo
  • 684
  • 3
  • 8
  • 25
Palkesh Jain
  • 412
  • 4
  • 12
  • Problem with `in.readArray(UINode.class.getClassLoader());`, because `UINode` doesn't have `public static final Creator CREATOR` as it's abstract class – ConstOrVar Oct 17 '18 at 10:20
  • @ConstOrVar replaced ```in.readArray(UINode.class.getClassLoader());``` with ```in.readArray(Node.class.getClassLoader());``` . But doesn't work – Palkesh Jain Oct 22 '18 at 12:30

0 Answers0