[FIXED] How to close a fragment manually in android NavigationComponent

Issue

I’m switched to NavigationComponent and i don’t know how close fragments manually using this component, in activities we have finish() method that close an activity, i need to do similar thing like this in NavigationComponent.

Solution

you can use below line in Fragment class:

getActivity().getParentFragmentManager().popBackStack();

or
if you are in an activity then you can use

getParentFragmentManager().popBackStack();

Answered By – Ketan Patel

Answer Checked By – Katrina (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published