I am new to android and I want to understand what is the best way to write clean code.
I have the following example:
ActivityA ---> FragmentA (main UI window the user sees)
then on a user's action
FragmentA --->starts---> ActivityB-->FragmentB (the next window the user sees and hides previous one)
then on a user's click:
FragmentB---> starts ---> ActivityC-->FragmentC (the next window the user see that hides the rest)
So at the last step the user sees the layout of FramentC.
In FragmentC
in order to populate the widgets of the layout properly I need some data that are available in FragmentA
.
What I do now is:
Pass the data as extras in the intent to FragmentB
. Some of these are actually needed by FragmentB
but others are not, and are passed to FragmentB
so that subsequently they are passed to FragmentC
via FragmentB
(again by intent/extra) if the user actually presses the button that opens up FragmentC
's layout
Question:
1) It works but I was wondering if the fact that I pass in the extras of intent to FragmentB
data that it does not really need is wrong/hack and there is a better/standard solution
2) When passing data among fragments are these data copies or a single copy is passed arround? I am not clear on that. E.g. in my example if I have a really big object passed from FragmentA
to FragmentB
(does not need it) and then FragmentB
passes it to FragmentC
(does need it) do I eventually have occupied 3 x size of the object?