我有活动A和B,都继承自BaseActivity类。活动A处理多个片段,并从其中一个片段启动活动B.在Activiy B的onCreate方法中,我调用以下方法:
addFragmentWithAnimation(ExampleFragment.newInstance(), R.anim.custom_slide_in_bottom, 0 , true);
由Base Activity类接收:
@Override
public void addFragmentWithAnimation(Fragment fragment, int i, int i1, boolean isInBackStack) {
FragmentManager fManager = getSupportFragmentManager();
fManager.executePendingTransactions();
FragmentTransaction transaction = fManager.beginTransaction();
transaction.setCustomAnimations(i, i1);
transaction.add(R.id.container, fragment);
if (isInBackStack) {
transaction.addToBackStack(fragment.getClass().getCanonicalName());
}
transaction.commit();
}
因此,将一个ExampleFragment添加到活动中,并显示底部动画中的幻灯片。然后ExampleFragment调用与Example2Fragment相同的方法,但在我将其删除之前,如下所示
@Override
public void closeFragmentWithAnimation(Fragment fragment, int i, boolean isInBackStack) {
FragmentManager fManager = getSupportFragmentManager();
fManager.executePendingTransactions();
FragmentTransaction transaction = fManager.beginTransaction();
transaction.setCustomAnimations(0, i);
transaction.remove(fragment);
if (isInBackStack) {
transaction.addToBackStack(fragment.getClass().getCanonicalName());
}
transaction.commit();
}
从Example2Fragment中调用它。我想强调两个交易都被添加到后台 到目前为止一切顺利,问题是当我按下后栈按钮时。当预期的行为登陆ExampleFragment
时,它返回到没有片段的空白活动后堆如何真正起作用?我在这里失踪了什么?
感谢