Office Hours — Today, October 17

Thursday, October 15

Mark M.
has entered the room
Oct 17
7:25 PM
Mark M.
turned on guest access
ry
has entered the room
Mark M.
hello, ry!
how can I help you today?
ry
Hi mark
I just have some questions relating to my app
7:30 PM
ry
I'm trying to extend the model fragment architecture from the tutorial
And i'm wondering if that's the best way to do it... because I have multiple screens which need to access its own instance of the model fragment
Mark M.
well, a model fragment is designed to help manage the model objects for one activity
you can say that you have several activities sharing the same model fragment class
ry
Yes, same class, but its own instance of each model fragment
Mark M.
however, if they are all working off of the same model objects, that begs the question of why they are separate activities in the first place
I would typically expect different activities to need different model fragment classes, just because they would be working with different facets of your overall data
ry
I want to enable the back button for users
and they are fragments not activities
Mark M.
ah, sorry -- when you wrote "multiple screens", I inferred that you meant multiple activities
ry
so the user can go to a new screen, which is the same activity but different fragments, and i want each fragment to have its own model fragment instance
Mark M.
um, I don't know how you are going to do that
ry
it all feels a bit messy... i'm not sure if this is a good way
Mark M.
the reason for a model fragment is to centralize activity-level things like configuration changes
7:35 PM
Mark M.
off the cuff, I have not really thought about trying to have a model fragment per fragment in a multi-fragment activity
7:35 PM
Mark M.
I suppose there is nothing stopping you from doing that, so long as you can keep track of unique tags for each model fragment instance
I'm not completely certain what you're gaining over having a single model fragment that happens to hold distinct portions of data for the active fragments
ry
hmm... yea. youre right, i just need the model fragment to hold an arraylist for each fragment. so i could just put all those arrays in one model fragment instance
Mark M.
right
ry
i'm also having trouble using findfragmentbytag inside of a fragment to get the instance of the model fragment that i've created in the activity. do you know off the top of your head if there's a common mistake i'm making?
Mark M.
are you using nested fragments (e.g., getChildFragmentManager())?
if yes, your model fragment is probably in the activity's FragmentManager, not one of the fragment's child FragmentManagers
7:40 PM
ry
all the fragments are created by that one activity, and i'm using getsupportfragmentmanager in my activity and in my fragments
Mark M.
then, off the cuff, I'm not sure what might be causing lookup problems, sorry
ry
ok, i'll keep trying to debug it
thank you for the help
Mark M.
you are very welcome
ry
has left the room
8:30 PM
Mark M.
turned off guest access

Thursday, October 15

 

Office Hours

People in this transcript

  • Mark Murphy
  • ry