ViewPager2 测试发现,设置setAdapter 后并不会销毁之前添加进来的fragment, 需要手动调用
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction tran = fragmentManager.beginTransaction(); tran.remove(fragment); tran.commitAllowingStateLoss();
循环移除fragment 才可以销毁