gpt4 book ai didi

android - 替换事务中的 fragment 后会发生什么

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

我想知道

getFragmentManager()
.beginTransaction()
.replace(
R.id.main,
Fragment.instantiate(LoadingScreen.this,
"com.myapp.fragments.fragment1",
bundle)).commit();

稍后我们调用

  getFragmentManager()
.beginTransaction()
.replace(
R.id.main,
Fragment.instantiate(LoadingScreen.this,
"com.myapp.fragments.fragment2",
bundle)).commit();

Fragment1 View 发生了什么?它会自动销毁吗?我们是否必须对此管理任何垃圾收集?

亲切的问候

最佳答案

根据 Android Developers 上的注释:

When you remove or replace a fragment and add the transaction to the back stack, the fragment that is removed is stopped (not destroyed). If the user navigates back to restore the fragment, it restarts. If you do not add the transaction to the back stack, then the fragment is destroyed when removed or replaced.

关于android - 替换事务中的 fragment 后会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26829721/

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