Passing an Object to Fragment or DialogFragment upon Instantiation

前端 未结 4 2176
春和景丽
春和景丽 2021-02-07 15:47

I\'m trying to work out the correct way to pass in an Object to a Fragment or DialogFragment without breaking the \'empty constructor\' rule.

For example I have created

4条回答
  •  失恋的感觉
    2021-02-07 16:35

    You could always use a nice JSON library like GSON or Genson for serializing objects - it is my goto approach for any remotely complex object. GSON is slightly more compact for simple operations but if you have any sort of inheritance / polymorphism in your views, I would highly recommend Genson. You can have a ctr with argument aslong as you document them.

    https://code.google.com/p/genson/ - Get the JAR in the download section.

提交回复
热议问题