Fragment isAdded() returns false on an already added Fragment

前端 未结 2 966
离开以前
离开以前 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.

提交回复
热议问题