Receive result from DialogFragment

I am using DialogFragments for a number of things: choosing item from list, entering text.

What is the best way to return a value (i.e. a string or an item from a list) back to the calling activity/fragment?

Currently I am making the calling activity implement DismissListener and giving the DialogFragment a reference to the activity. The Dialog then calls the OnDimiss method in the activity and the activity grabs the result from the DialogFragment object. Very messy and it doesn’t work on configuration change (orientation change) as the DialogFragment loses the reference to the activity.

Thanks for any help.

15 Answers
15

Leave a Comment