Android Programming The Big Nerd Ranch Guide, 3rd Edition

(Brent) #1
Returning data to CrimeFragment

243

More flexibility in presenting a DialogFragment


Using onActivityResult(...) to send data back to a target fragment is especially nice when you are
writing an app that needs lots of input from the user and more room to ask for it – and you want the
app working well on phones and tablets.


On a phone, you do not have much screen real estate, so you would likely use an activity with a full-
screen fragment to ask the user for input. This child activity would be started by a fragment of the
parent activity calling startActivityForResult(...). On the death of the child activity, the parent
activity would receive a call to onActivityResult(...), which would be forwarded to the fragment that
started the child activity (Figure 12.11).


Figure 12.11  Inter-activity communication on phones


http://www.ebook3000.com

Free download pdf