Fragment addToBackStack() and popBackStackImmediate() not working

前端 未结 6 2000
清酒与你
清酒与你 2020-12-08 20:00

I am currently building an application for Android (14 <= SDK <= 21) by using one ActionBarActivity and more Fragments, such as ListFra

6条回答
  •  囚心锁ツ
    2020-12-08 20:13

    Try this (Note add not replace for fragmentA, and addToBackStack() for fragmentB)

    StopItemFragment list = StopItemFragment.newInstance(null); //A - extends ListFragment
            fragmentManager.beginTransaction()
                .add(R.id.content_frame, list)
                .commit();
    

    and

    StopFragment fragment = StopFragment.newInstance(null, null); //B - extends Fragment
       ...
       fragmentManager.beginTransaction()
            .replace(R.id.content_frame, fragment)
            .addToBackStack("FragmentB")
            .commit();
    

提交回复
热议问题