I have this Activity (Foo
) that hosts this Fragment (Bar
) which is filled with information coming from another Activity.
The process goes like this:
MainActivity → Bundle → Foo → Bar → gather data and return to MainActivity.
- Should I store that information in private fields of the
Foo
Activity atonCreate
, and just making the Fragment use them? - Should I pass the Bundle directly to my
Bar
Fragment as arguments? - Should I make a new Bundle out of the received one and pass the new Bundle to the Fragment?
- Should I completely replace the whole fragment each time data changes or should I only update the changing views, when data isn't directly being provided by the user e.g. by a Dialog?
The fragment only has one view whose value may be changed, but this value has to be formatted (it's received from a Dialog).
- Should I store only that changing value in a private field of my Activity and access it when I have to update the view or retrieve the result of the Activity when it finishes?
- Should I implement an Adapter on such view so it stores the value, but shows the formatted information to the user?
- Should I store the formatted value in the view and parse it back to the raw value I need to receive the information it contains when I have to return the gathered data?
- Should I store all the information gathered, replace the fragment for a new one with the information previously collected (by using one of the methods in the first section)?
Is there a convention that covers passing data from one activity to another, and how the data may be used through the lifecyle of the second activity? Or at least some kind of best practices for this?
EDIT:
I'm aware of how to do all of the above points, so I'm not asking for code; the thing is that I find a lack of homogeneity between how I pass the data from the main activity to the child activity, how I pass it to the fragment and how do I update the fragment in the case that data is changed.