Fragment Arguments
CrimeListFragment now notifies its hosting activity (MainActivity) when a crime is selected and passes along the ID of the selected crime.
That is all fine and dandy. But what you really need is a way to pass the selected crime ID from MainActivity to CrimeFragment. This way, CrimeFragment can pull data for that crime from the database and populate the UI with that data.
Fragment arguments offer a solution to this problem – they allow you to stash pieces of data someplace that belongs to the fragment. The “someplace” that belongs to a fragment is known as its arguments bundle. The fragment can retrieve data from the arguments bundle without relying on its parent activity or some other outside source.
Fragment ...
Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.