java - Standard approach to pass data among chain of fragments -
i new android , want understand best way write clean code.
have following example:
activitya ---> fragmenta (main ui window user sees)
then on user's action
fragmenta --->starts---> activityb-->fragmentb (the next window user sees , hides previous one)
then on user's click:
fragmentb---> starts ---> activityc-->fragmentc (the next window user see hides rest)
so @ last step user sees layout of framentc.
in fragmentc
in order populate widgets of layout need data available in fragmenta
.
what is:
pass data extras in intent fragmentb
. of these needed fragmentb
others not, , passed fragmentb
subsequently passed fragmentc
via fragmentb
(again intent/extra) if user presses button opens fragmentc
's layout
question:
1) works wondering if fact pass in extras of intent fragmentb
data not need wrong/hack , there better/standard solution
2) when passing data among fragments these data copies or single copy passed arround? not clear on that. e.g. in example if have big object passed fragmenta
fragmentb
(does not need it) , fragmentb
passes fragmentc
(does need it) have occupied 3 x size of object?
1)intent right way it. fact need pass in unneeded data sounds may have tight coupling in fragments may bad flexibility later on. since data (i assume) related make sense abstract class , make class parcable or serializable in order reduce coupling.
2)assuming use parcable/serializable, they're copied. because intent doesn't have go app, system turn data form can read second application. (i'm not sure format uses, imagine json. practical purposes may be).
Comments
Post a Comment