我将一个应用程序来使用通过兼容性库的片段。 现在目前我有一些活动(ABCD)的链到彼此,D有一个按钮OK,当pressed通话结束,然后上升时onActivityResult额外地破坏C和B。
有关我的pre Honycomb片段版本每一项活动是有效的片段房颤的Bf比照Df的一个包装。所有的活动都通过startActivityForResult和onActivityResult在每个片段的推出可以愉快地调用getActivity()。完成
这是我有但现在的问题是在我的蜂巢版本,我只有一个活动,A和片段BF,比照,东菱使用FragmentManager加载。
我不明白什么是做什么的Df的时候'OK'是pressed,以消除碎片DF,CF和详细的展望?
我试过有片段弹出自行关闭栈,但这导致了异常。 onActivityResult是无用的,因为我使用startActivityForResult没有装起来的片段。
我在想这个完全错误的方式?我应该实现某种监听器与任父片段或活动,才能使用事务管理器做弹出通信?
解决方案我不明白的是做Df的什么什么的时候OK是pssed为了消除碎片$ P $ DF,比照,和BF?
步骤#1:!哟,我们得到了确定单击有Df的告诉ð通过调用一个方法,无论是在活动本身,或者在由活动提供的接口实例
步骤#2:有d通过 FragmentManager
删除片段
的托管活性(D)是它知道哪些其他片段中的活性(相对于在其他活动是)之一。因此,在片段可能影响的片段组合事件应该被传播到活动中,将进行相应的协调动作。
I'm converting an app to use fragments using the compatibility library. Now currently I have a number of activities (A B C D) which chain onto one another, D has a button 'OK' which when pressed calls finish which then bubbles up through onActivityResult to additionally destroy C and B.
For my pre Honycomb fragment version each activity is effectively a wrapper on fragments Af Bf Cf Df. All activities are launched via startActivityForResult and onActivityResult within each of the fragments can happily call getActivity().finish
The problem that I am having though is in my Honeycomb version I only have one activity, A, and fragments Bf, Cf, Df are loaded using the FragmentManager.
What I don't understand is what to do in Df when 'OK' is pressed in order to remove fragments Df, Cf, and Bf?
I tried having the fragment popping itself off the stack but this resulted in an exception. onActivityResult is useless because I have not loaded up the fragment using startActivityForResult.
Am I thinking about this completely the wrong way? Should I be implementing some sort of listener that communicates with either the parent fragment or activity in order to do the pop using the transaction manager?
解决方案What I don't understand is what to do in Df when 'OK' is pressed in order to remove fragments Df, Cf, and Bf?
Step #1: Have Df tell D "yo! we got the OK click!" via calling a method, either on the activity itself, or on an interface instance supplied by the activity.
Step #2: Have D remove the fragments via FragmentManager
.
The hosting activity (D) is the one that knows what other fragments are in the activity (vs. being in other activities). Hence, in-fragment events that might affect the fragment mix should be propagated to the activity, which will make the appropriate orchestration moves.