美文网首页
Fragment already added异常解决方案

Fragment already added异常解决方案

作者: 杨小贱_892e | 来源:发表于2019-04-12 23:29 被阅读0次

    Fragment showFg;

    boolean isFirstCreated = false;

    if (!fragment.isAdded() &&null == getSupportFragmentManager().findFragmentByTag("TAG" +tagPage)

    &&isFristCreated) {

    if (showFg !=null) {

    ft.hide(showFg).add(fragment, "TAG" +tagPage);

        }else {

    ft.add(fragment, "TAG" +tagPage);

        }

    }else {//已經載入進容器裡去了....

        if (showFg !=null) {

    ft.hide(showFg).show(unlockConfirmDialog);

        }else {

    ft.show(unlockConfirmDialog);

        }

    }

    showFg =fragment;

    if (!isFinishing()) {

    ft.commitAllowingStateLoss();

        getSupportFragmentManager().executePendingTransactions();

    }

    新建Fragment的时候将isFristCreated置为true。

    Fragment fragment =new Fragment();

    isFristCreated =true;

    亲测有效。。 

    相关文章

      网友评论

          本文标题:Fragment already added异常解决方案

          本文链接:https://www.haomeiwen.com/subject/uhnslxtx.html