动态加载fragment以后,调用了remove方法移除Fragment,在返回来的时候报 Attempt to write to field 'int android.support.v4.app.Fragment.mNextAnim' 空指针

这是因为,在Fragment为null的时候就调用的remove,解决办法是remove的时候返回是否Fragment为null,为null就不用执行remove方法

It's because you are calling remove() add() etc. methods with null value.

and please keep in mind that replace() = remove()->add() one by one.

 

 

FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        for (int i = 0; i < listFmName.size(); i++) {
            if(manager.findFragmentByTag(listFmName.get(i))!=null){
                transaction.remove(manager.findFragmentByTag(listFmName.get(i)));
            }
        }
        listFmName.clear();
        transaction.commitAllowingStateLoss();