Reputation: 373
I am having trouble understanding the merit of storing information in an arguments bundle, rather than just using an intent and putting an extra in it. The book I am using states that "CrimeFragment is no longer a reusable building block because it expects that it will always be hosted by an activity whose Intent defines an extra named EXTRA_CRIME_ID...it means that CrimeFragment, as currently written, cannot be used with just any activity".
In the book's implementation of this application, an activity called CrimeActivity creates a fragment called CrimeFragment. I don't see why any other activity would want to call CrimeFragment. What's the point?
So, two questions: the merit of using arguments bundle, and why there isn't just a 1 to 1 correspondence between a fragment and an activity.
Thanks!!
Upvotes: 0
Views: 430
Reputation: 2600
Fragments are supposed to b e reusable components. If you don't require the same layout and code to be at someplace else as well, its better to implement that layout in the activity.
If your fragment is dependent on the activity's intent, it takes away the reusability component. Make your fragment standalone. Better use a bundle and set it as an argument
Upvotes: 1