标签:android for cti on c ad r as tt
1、remove,add,replace
remove:移除fragment,被移除的fragment会销毁掉,包括实例和界面。
add:
add(int containerViewId, Fragment fragment)
Calls add(int, Fragment, String) with a null tag.
add(Fragment fragment, String tag)
Calls add(int, Fragment, String) with a 0 containerViewId.
add(int containerViewId, Fragment fragment, String tag)
Add a fragment to the activity state.
replace:等同于remove+add。
说明:往同一个containerViewId中replace会移除掉旧的fragment,包括实例和界面,然后add新的fragment,只会有一个fragment存在。
add会往同一个containerViewId中添加多个fragment,包括实例和界面,后加进去的会叠加在前面的fragment的上面,可以有多个fragment存在。
2、backstack fragment的后退栈
在调用add或者replace方法之后,调用commit方法之前加上addToBackStack会将当前的fragment加入到backstack。
说明:在调用replace方法前,如果某个fragment已加入到后退栈,然后这个时候调用replace被别的fragment替换了,此fragment也就销毁了,但是
还是可以按返回键从后退栈中弹出,其实也就是说fragment和后退栈中的fragment不是一回事。
3、清空backstack方法
popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)。
public static final int POP_BACK_STACK_INCLUSIVE
Added in API level 11
Flag for popBackStack(String, int) and popBackStack(int, int): If set, and the name or ID of a back stack entry has been supplied, then all matching entries will be consumed until one that doesn‘t match is found or the bottom of the stack is reached. Otherwise, all entries up to but not including that entry will be removed.
标签:android for cti on c ad r as tt
原文地址:http://www.cnblogs.com/yushilong/p/3979602.html