Christophe Beyls
1 min readAug 20, 2020

--

A class should never accept a Parcel as primary constructor parameter. You can however create a secondary constructor which accepts a Parcel, reads all the fields from the Parcel then pass them to the primary constructor.

If you inherit from such a class, you'll still have to deal with the limitations explained in the article: if you want to use @Parcelize with the subclass, you'll end up with duplicated fields unless all the primary constructor fields of the parent class are abstract.

--

--

Christophe Beyls
Christophe Beyls

Written by Christophe Beyls

Android developer from Belgium, blogging about advanced programming topics.

No responses yet