How to destroy Fragment?

前端 未结 5 1456
北恋
北恋 2020-12-13 17:21

I have one Activity. The Activity has two Fragments. Fragment A is Menu. Fragment B is Detail.

I try to Make other Fragment C

5条回答
  •  执念已碎
    2020-12-13 17:43

    If you are in the fragment itself, you need to call this. Your fragment needs to be the fragment that is being called. Enter code:

    getFragmentManager().beginTransaction().remove(yourFragment).commitAllowingStateLoss();
    

    or if you are using supportLib, then you need to call:

    getSupportFragmentManager().beginTransaction().remove(yourFragment).commitAllowingStateLoss();
    

提交回复
热议问题