我移植我的Android应用程序,以蜂窝我才能使用片段做了一次大的重构。在我的previous版本,当我pressed的主页按钮,我以前做的一个ACTIVITY_CLEAR_TOP以重置回堆栈。
I ported my Android app to honeycomb and I did a big refactor in order to use fragments. In my previous version, when I pressed the Home button I used to do a ACTIVITY_CLEAR_TOP in order to reset the back stack.
现在我的应用程序仅仅是与多个片段(fragments)一个活动,所以当我preSS的主页按钮,我只需更换里面的片段之一。我怎样才能清除,而不必使用startActivity与ACTIVITY_CLEAR_TOP标志我的背部栈?
Now my app is just a single Activity with multiple fragmens, so when I press the Home button I just replace one of the fragments inside it. How can I clear my back stack without having to use startActivity with the ACTIVITY_CLEAR_TOP flag?
I类似这里发布的内容
这是勒夫的回答,从戴安娜Hackborn:
From Joachim's answer, from Dianne Hackborn:
http://groups.google.com/group/android-developers/browse_thread/thread/d2a5c203dad6ec42
我最终只使用:
FragmentManager fm = getActivity().getSupportFragmentManager();
for(int i = 0; i < fm.getBackStackEntryCount(); ++i) {
fm.popBackStack();
}
但也同样使用了类似:
But could equally have used something like:
FragmentManager.popBackStack(String name, FragmentManager.POP_BACK_STACK_INCLUSIVE)
这将弹出所有状态到已命名的。然后,您只需更换片段,你想要什么
Which will pop all states up to the named one. You can then just replace the fragment with what you want