Search code examples
androidclassparsingparcelable

Make a class with several objects of multiple subclasses parcelable in Android


I have a class containing 2 subclasses and have several instances of those subclasses.

ClassA{
private ClassB obj1;
private ClassB obj2;
private ClassC obj3;
private ClassC obj4;
private ClassC obj5;
private ClassC obj6;

private class ClassB{}
private class ClassC{}
}

Is it possible to make such a construct parcelable? How would I do that or what are the alternatives?

Thank you for any help you can offer!


Solution

  • First add a Android Studio Plugin for creating parcelable class.

    Goto

    File -> Settings -> Plugins and search 'parcelable' and click on Browse and install Android Parcelable Code generator.

    now open your class which you want to make parcelable and then goto

    Code -> Generate (ALT+Insert)

    and select Parcelable, select the field you want to be parcelable and thats it, it will generate the required code.

    Do this for all the sub classes.