What is the best way to pass a message from one fragment to its parent (equivalent to onActivityResult)

OK. I know that I think about it wrong, but ...

A) I have an active Fragment F1 boot that loads a F2 fragment. F2 performs an action that should lead to its closure, and then F1 performs a certain action depending on how it was closed.

B) Now, since I also support a single window, without fragment, version F1 also loads F2 indirectly through a call to startActivityForResult. This means that upon completion of the shell operation, F2 F1 receives an onActivityResult call, and F1 can do what it needs.

However, I try my best to find the best way to realize what I want (A). I have F2 returning activity A to pop out of the stack. Should I then watch the F1 message to do what I need? Alternatively (I suppose F1 might be responsible for saying F2 from the stack).

I am wondering if I am correctly on the right path for sending messages back and forth through parental activity, or is there a more direct way F1 responds to F2, doing something that needs to be closed, and F1 does what it needs.

Thanks in advance. Peter.

+3
source share
2 answers

, . .

, , onActivityResult() , "" onActivityResult() . , Fragment.setTargetFragment() , .

+7

A loading F1, F2

IMHO, . , . , - , .

F2, A, . F1 , ?

.

, F1, F2, -, , F1 , .

, F1 , F2 , . - F1, (, /), F1 , , , F1 ( ), , F2 , . , F2 , , .

"F2 , ", F2 DialogFragment.

+7

All Articles