gpt4 book ai didi

android - 结束 fragment

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:32 37 4
gpt4 key购买 nike

所以我已经了解了如何打开 fragment。这是我的困境。我的 view 旁边有一个元素列表(元素周期表元素)。当您选择一个元素时,它会显示它的信息。

我的问题是我需要能够从(我们称之为详细信息 fragment )中删除 view 并将其从堆栈中删除,这样我就没有很大的内存备份。

调用新的 fragment 替换它时,如何将它从堆栈中移除?

最佳答案

您可以使用FragmentTransaction#remove() 方法删除 fragment 。此方法还会从它附加到的容器中删除 View 。

但是,从 fragment 文档中:

Stopped: The fragment is not visible. Either the host activity has been stopped or the fragment has been removed from the activity but added to the back stack. A stopped fragment is still alive (all state and member information is retained by the system). However, it is no longer visible to the user and will be killed if the activity is killed.

如果您将该 fragment 添加到返回堆栈,则在 Activity 被终止之前它不会被终止。

关于android - 结束 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5333378/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com