add()和REPLACE()片段的方法之间的基本区别 [英] Basic difference between add() and replace() method of Fragment
问题描述
的更换和添加方法的工作方式不同,而且是没有任何真实的生活场景,我们需要这些方法用于特定目的。
How do Fragment
's replace and add methods work differently, and is there any real life scenario where we would need these methods for specific purposes.
推荐答案
的重要区别是:
替换
删除现有的片段,并增加了一个新的片段。
replace
removes the existing fragment and adds a new fragment..
但添加
保留现有的片段,并增加了一个新的片段,这意味着现有的片段将被激活,他们不会是在暂停状态,因此,当一个后退按钮为pressed onCreateView()
不要求现有的片段(这是有加入新片段之前,片段)。
but add
retains the existing fragments and adds a new fragment that means existing fragment will be active and they wont be in 'paused' state hence when a back button is pressed onCreateView()
is not called for the existing fragment(the fragment which was there before new fragment was added).
有关更多信息,只需访问<一个href=\"http://stackoverflow.com/questions/18634207/difference-between-add-replace-and-addtobackstack\">this交谈。
For more information just visit this conversation.
这篇关于add()和REPLACE()片段的方法之间的基本区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!