Android – how best to pass messages from a fragment to its parent (onactivityresult equivalent)

OK, I know I may think about it in the wrong way, but

A) I have activity a loading fragment F1 loading fragment F2. F2 performs an action that should cause it to be closed, and then F1 performs an action according to its closing method

B) Now, because I also support a single pane, non fragment, version F1 also indirectly loads F2 through the startactivityforresult call. This means that when the wrapper activity of F2 is completed, F1 receives the onactivityresult call, and F1 can perform what it needs to do

However, it's hard for me to see the best way to achieve what I want (a). I have F2 callback activity a to pop it out of the stack. So should I consider passing information to F1 to do what it needs to do? Or (I think F1 may be responsible for popping F2 off the stack)

What I want to know is whether I pass messages back and forth through the parent activity on the right track, or whether there is a more direct way for F1 to respond to F2 and execute what needs to be closed. What does F1 do

Thanks in advance, Peter

resolvent:

If your clips are tightly tied together, do not run them in separate activities. For single pane cases, you only need to switch clips in one activity

Otherwise, if you really want to separate them between activities, you need to use the onactivityresult() model to propagate the results and "simulate" it by calling the onactivityresult() of the first fragment a second time in the case of two panes. Note that fragment. Settargetfragment() contains a request code parameter to facilitate this operation

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>