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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.