Passing Data Between Two Fragments

In Chapter 13, you passed a crime’s ID from CrimeListFragment to CrimeDetailFragment. Passing data to DialogFragment destinations works just the same.

What is different this time is that you are also passing a result back to CrimeDetailFragment: When the user selects a new date, CrimeDetailFragment needs the date to update its UI. Instead of using the Navigation library to handle that communication, this time you will rely on the Fragment Results API. Its usage is slightly different than the Activity Results API you used back in Chapter 7, but the concepts are the same, so you should feel right at home.

The conversation between your fragments will look like Figure 14.4. When the DatePickerFragment ...

Get Android Programming: The Big Nerd Ranch Guide, 5th 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.