Fragment isAdded() returns false on an already added Fragment

前端 未结 2 949
离开以前
离开以前 2020-12-15 06:57

I have this neat function:

private void addMapFragment(){
    if(!mapFragment.isAdded()){
        FragmentTransaction ft = getFragmentManager().beginTransact         


        
相关标签:
2条回答
  • 2020-12-15 07:23

    FragmentTransactions are committed asynchronously. Therefore, you need to call

    getFragmentManager().executePendingTransactions();
    

    before you call

    Fragment.isAdded();
    

    That way, you can make sure that everything is up to date.

    0 讨论(0)
  • 2020-12-15 07:28

    Instead, check getSupportFragmentManager.findFragmentById() and see if you are getting the expected fragment back. If now you can add and commit.

    0 讨论(0)
提交回复
热议问题