Passing Data Between Two Fragments

You have passed data between two activities using intent extras, passed data between a fragment and an activity using a callbacks interface, and passed data from an activity to a fragment using fragment arguments. Now you need to pass data between two fragments that are hosted by the same activity – CrimeFragment and DatePickerFragment (Figure 13.4).

Figure 13.4  Conversation between CrimeFragment and DatePickerFragment

Conversation between CrimeFragment and DatePickerFragment

To get the Crime’s date to DatePickerFragment, you are going to write a newInstance(Date) function and make the Date an argument on the fragment.

To get the new date back ...

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.