TrackGroup implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(length); for (int i = 0; i < length; i++) { dest.writeParcelable(formats[i], 0); } } TrackGroup(Format... formats);   TrackGroup(Parcel in); Format getFormat(int index); @SuppressWarnings("ReferenceEquality") int indexOf(Format format); @Override int hashCode(); @Override boolean equals(@Nullable Object obj); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); final int length; static final Parcelable.Creator<TrackGroup> CREATOR; }
@Test public void testParcelable() { Format format1 = Format.createSampleFormat("1", MimeTypes.VIDEO_H264, 0); Format format2 = Format.createSampleFormat("2", MimeTypes.AUDIO_AAC, 0); TrackGroup trackGroupToParcel = new TrackGroup(format1, format2); Parcel parcel = Parcel.obtain(); trackGroupToParcel.writeToParcel(parcel, 0); parcel.setDataPosition(0); TrackGroup trackGroupFromParcel = TrackGroup.CREATOR.createFromParcel(parcel); assertThat(trackGroupFromParcel).isEqualTo(trackGroupToParcel); parcel.recycle(); }