因为项目需求,需要在最后关机的时候清空所有回退栈中的Fragment。
当时的想法就是找到一个Fragment的方法或者是FragmentManger的方法,然后调用这个方法,将其清空。
接下来就是照这个方法,终于找到一个方法getSupportFragmentManager().getFragments().clear();
然后就是尝试,把代码加进去
if (getSupportFragmentManager().getFragments() != null
&& getSupportFragmentManager().getFragments().size() > 0) {
getSupportFragmentManager().getFragments().clear();
结果是可以清空的。但是问题也来了,程序总是崩溃,报一个数组超标的错误,然后就是调试
怎么也找不到错误所在,因为在清空Fragment代码中压根就没有数组(arraylist),知道最后就是
source not found。郁闷了。
这个问题暂且搁下,另找方法。重新生成Fragment实例吧,看看成不成。上代码
mAutoMassageLayout = (FrameLayout) findViewById(R.id.layout_auto);
mManualMassageLayout = (FrameLayout) findViewById(R.id.layout_manual);
mHolographicHandMassageLayout = (FrameLayout) findViewById(R.id.layout_holographic_hand)