在addtobackstack之后,Oncreateview没有调用

时间:2018-01-06 17:34:42

标签: java android android-fragments fragment android-fragmentactivity

根据片段生命周期,我想:

- Add fragment A + addToBackStack(null)
       |
- Add fragment B + addToBackStack(null)

当我从BI按回来时,期望Oncreateview应按照生命周期进行调用,但看起来似乎:它只是弹出后台,但没有一种方法是调用。所以如何识别片段A中的反压?

这是我简单的代码格式:

// I am calling fragment like this way 

      Fragment fragmentb=new FragmentB();
            FragmentManager fragmentManager=getFragmentManager();
            FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
            fragmentTransaction.add(R.id.fragment,fragmentb).addToBackStack(null);
            fragmentTransaction.commit();

1 个答案:

答案 0 :(得分:0)

      Fragment fragmentb=new FragmentB();
            FragmentManager fragmentManager=getFragmentManager();
            FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.fragment,fragmentb);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();