一个片段的Android单实例 [英] Android Single Instance of a Fragment
问题描述
有没有一种方法,当我们使用 ft.addToBackStack(NULL);
我们只有一个实例添加到BackStack?添加相同片段的多个实例来返回堆栈将创建在用户presses后退按钮杂波?
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?
推荐答案
您可以尝试一个字符串设置为addToBackStack方法。前
You could try setting a string to the addToBackStack method. Ex
ft.addToBackStack("fragmentA");
后来那么,如果你coing再次插入相同的片段。你将它添加到布局之前做到这一点。
Later then, if you are coing to insert that same fragment again. You do this before adding it to the layout.
getFragmentManager().popBackStack("fragmentA", FragmentManager.POP_BACK_STACK_INCLUSIVE);
<一个href=\"http://developer.android.com/reference/android/app/FragmentManager.html#popBackStack%28java.lang.String,%20int%29\" rel=\"nofollow\">http://developer.android.com/reference/android/app/FragmentManager.html#popBackStack(java.lang.String, INT)
这篇关于一个片段的Android单实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!