Remove old Fragment from fragment manager

后端 未结 5 1880
孤城傲影
孤城傲影 2020-11-27 15:26

I\'m trying to learn how to use Fragments in android. I\'m trying to remove old fragment when new fragment is calling in android.

5条回答
  •  囚心锁ツ
    2020-11-27 16:15

    I had the same issue to remove old fragments. I ended up clearing the layout that contained the fragments.

    LinearLayout layout = (LinearLayout) a.findViewById(R.id.layoutDeviceList);
    layout.removeAllViewsInLayout();
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ...
    

    I do not know if this creates leaks, but it works for me.

提交回复
热议问题