为什么FragmentManager的getBackStackEntryCount()返回零?FragmentManager、getBackStackEntryCount

2023-09-06 03:17:32 作者:首宠

private static void changeFragment(Fragment f, boolean init) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.info_content, f,f.getClass().getName());
        if(!init){
            ft.addToBackStack(null);
        }
        ft.commit();
    }

当我想要得到的协议栈通过调用fm.getBackStackEntryCount(COUT),它返回零?

when I want to get the stack cout by call fm.getBackStackEntryCount(), it returns zero?

推荐答案

您得叫 fm.executePendingTransactions() ft.commit ()或之前 fm.getBackStackEntryCount()。由于提交()只时间表以后通的交易。

You have to call a fm.executePendingTransactions() after ft.commit() or before fm.getBackStackEntryCount(). Because the commit() only schedules the transactions for a later pass.