0

If I have an object called "EditorialCollection" and it implements parcelable why can't I debug into the overrided methods like writeToParcel?

protected EditorialCollection(Parcel in) {
        super(in);
//break point here:
        items = new ArrayList<>();
        in.readList(items, CollectionItem.class.getClassLoader());
        embedPagination = (EmbedPagination) in.readValue(EmbedPagination.class.getClassLoader());
    }

    @Override
    public int describeContents() {
        return 0;
    }
public static final Creator<EditorialCollection> CREATOR = new Creator<EditorialCollection>() {
    @Override
    public EditorialCollection createFromParcel(Parcel in) {
        return new EditorialCollection(in);
    }

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

I can't hit break points nor can I output logging there. Am I doing something wrong or can someone explain why logging/breakpoints won't work here.

Thanks, Reid

reidisaki
  • 1,525
  • 16
  • 29
  • How do you know that constructor is even being called? You have no `CREATOR` code here – OneCricketeer Apr 03 '17 at 21:47
  • Still not able to debug inside this class. the code is working but I just don't get why I can't step inside the class – reidisaki May 15 '17 at 16:18
  • Why is the constructor protected? Is it calling the default constructor? – OneCricketeer May 16 '17 at 15:56
  • I changed the access level to public but still can't get to this code. I'm using GSOn to create the objects, but I implemented parceleable to pass between activities. – reidisaki May 16 '17 at 21:49
  • Can you show a [mcve], please? – OneCricketeer May 17 '17 at 21:52
  • I found a SO post showing in detail that when you are using putParcelable and getParceleable, the creatFromParcel method won't be called. Only if the activity is destroyed will it call those parcelable methods. – reidisaki May 26 '17 at 16:51

2 Answers2

0

Parcel objects or Parcelable implementation objects cannot being debugged.

public final class Parcel {
    private static final boolean DEBUG_RECYCLE = false;
    private static final boolean DEBUG_ARRAY_MAP = false;
    private static final String TAG = "Parcel";
    .
    .
    .
} 
Joffrey Schmitz
  • 2,393
  • 3
  • 19
  • 28
0

You can use Parcelables.forceParcel(builder, CREATOR) method for testing Parcel classes.

But it is only available for Test Classes.

Also you can copy this func from Parcelables class. And you can try in java code:

public static <T extends Parcelable> T forceParcel(T parcelable, Creator<T> creator) {
   Parcel parcel = Parcel.obtain();
   try {
     parcelable.writeToParcel(parcel, 0);
     parcel.setDataPosition(0);
     return creator.createFromParcel(parcel);
   } finally {
     parcel.recycle();
   }
}
b.erdi
  • 386
  • 3
  • 12