androidandroid-studioandroidxfragmentmanager

Android Studio FragmentManger POP_BACK_STACK_INCLUSIVE


I'm imitating a project to study, and the original study,

activity?.supportFragmentManager!!.popBackStack(activity?.supportFragmentManager!!.getBackStackEntryAt(0).id, POP_BACK_STACK_INCLUSIVE)

it worked.

and now on my project I copied and pasted, and it's automatically changed like below

activity?.supportFragmentManager!!.popBackStack(activity?.supportFragmentManager!!.getBackStackEntryAt(0).id,FragmentManager.POP_BACK_STACK_INCLUSIVE)

the end of the code is different. and I must write FragmentManger.POP_BACK_STACK_INCLUSIVE, not just POP_BACK_STACK_INCLUSE. If I write only POP_BACK_STACK_INCLUSIVE, then it makes error.

I don't know why it's happened like this. WHY?


Solution

  • In the original project, the FragmentManager has been imported in the file, so you don't need to specify it again.

    import androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE
    

    Try to add it into the top of your file and see if it works. If not, you may find a similar line in your original project, copy that into your file and it should work