我正在尝试从片段管理器中删除一些片段。我使用以下代码来完成此任务:
FragmentTransaction transaction = fm.beginTransaction();
for (String fragmentTag : fragmentsToRemove) {
Fragment removedFragment = fm.findFragmentByTag(fragmentTag);
if (removedFragment != null)
transaction.remove(removedFragment);
}
transaction.commit();
fm.executePendingTransactions();
稍后,当我尝试重新添加已删除的片段时,我发现它仍然在片段管理器中:
if (fm.findFragmentByTag(nextFragmentTag) == null) {
mNextFragment = determineFragmentToSwitchTo(nextFragmentTag);
transaction.add(R.id.fragment_container, mNextFragment, nextFragmentTag);
} else {
transaction.show(mNextFragment);
}
transaction.addToBackStack(nextFragmentTag);
transaction.commit();
fm.executePendingTransactions();
上面的代码点击上面的语句,else总是被调用。什么是错的