Android Programming The Big Nerd Ranch Guide, 3rd Edition

(Brent) #1

Chapter 12  Dialogs


244

On a tablet, where you have plenty of room, it is often better to present a DialogFragment to the user
to get the same input. In this case, you set the target fragment and call show(...) on the dialog fragment.
When dismissed, the dialog fragment calls onActivityResult(...) on its target (Figure 12.12).


Figure 12.12  Inter-fragment communication on tablets


The fragment’s onActivityResult(...) will always be called, whether the fragment started an activity
or showed a dialog. So you can use the same code for different presentations.


When setting things up to use the same code for a full-screen fragment or a dialog fragment, you
can override DialogFragment.onCreateView(...) instead of onCreateDialog(...) to prepare for both
presentations.

Free download pdf