7

I am using GraphQL with my Android Project. I got into trouble when passing results(objects of the auto-generated class by Apollo in the build folder) to another activity by extras.

How can I make those auto-generated class parcelable?

Ivan Bila
  • 747
  • 7
  • 9
chathura
  • 3,362
  • 6
  • 41
  • 68
  • 2
    I don't think that's possible. IMHO, passing model objects via custom-`Parcelable` extras has never been a great plan. Put a repository around the Apollo-Android code, one that has appropriate caching (either in the repository or using Apollo-Android's caching). Pass identifiers between activities, and have activities obtain their models from the repository. – CommonsWare Mar 04 '18 at 16:09
  • @CommonsWare can you explain more about the repository thing and how it can be implemented? – chathura Mar 04 '18 at 16:14
  • 1
    There is a little bit of material on the repository pattern in [the Architecture Components' "Guide to App Architecture"](https://developer.android.com/topic/libraries/architecture/guide.html), though it's not very good. I have more material on it in one of my books -- [here is a preview of the chapter](https://commonsware.com/AndroidArch/previews/the-repository-pattern). I don't have other links for the repository pattern handy right now -- sorry! – CommonsWare Mar 04 '18 at 16:17

1 Answers1

3

Generated classes are not supposed to be edited since the changes would be ignored once the class is regenerated.

You have to create a model class that is parcelable and store the object in that model class, and then you can pass that object.

Ivan Bila
  • 747
  • 7
  • 9
Deepak
  • 77
  • 7
  • 3
    Its not about editing generating classes. It is about being able to pass these objects of generated classes from one fragment to another. This passing around is easy if the classes are parcelable – user882290 Dec 01 '21 at 04:44