Yes, the issue here is that we are passing back data to a fragment that already exists. Fragment arguments are used when you create a new fragment.
The real trick here is that we need a solution that works across the death and recreation of both of our fragments (CrimeFragment and the dialog fragment). The way we solve this problem in the book is with the target fragment API. Once we set CrimeFragment as the target fragment on the dialog, it will be re-connected for us across the death and recreation of these fragments (through rotation or low-memory death). Then, we can just call methods on the target fragment.
You can define your own methods if you want:
We chose to use the
onActivityResult method because every Fragment has this method and our dialog won’t need to know any specific details about the fragment it returns data to. Any fragment can use the date dialog.