5

Is there a way that when we use ft.addToBackStack(null); we only add a single instance to the BackStack? Adding multiple instances of the same fragment to the Back Stack creates a clutter when the user presses the Back Button?

4

1 回答 1

3

您可以尝试为 addToBackStack 方法设置一个字符串。前任

ft.addToBackStack("fragmentA");

稍后,如果您打算再次插入相同的片段。在将其添加到布局之前执行此操作。

getFragmentManager().popBackStack("fragmentA", FragmentManager.POP_BACK_STACK_INCLUSIVE);

http://developer.android.com/reference/android/app/FragmentManager.html#popBackStack(java.lang.String, int)

于 2013-08-29T17:39:25.510 回答