0

I have integrated Navigation component in my app. I'm using it along with Bottom Navigation.

I have 3 tabs [Home, Notification, Account]. Switching the navigation is working perfectly fine.

Problem for me lies here.   From Home fragment the app navigates to many other fragments Home -> FragA -> FragB -> FragC. But when i click on the Home icon in bottom navigation, I want to clear all the Fragments and come to the initial state. Currently Im coming to the home screen, but when i click back all previous fragments FragA -> FragB -> FragC are showing up.

How can this be achieved?

Not attaching any code as it's irrelevant

Anup Ammanavar
  • 322
  • 2
  • 14

1 Answers1

0

You can remove your fragments from fragmentManager:

getSupportFragmentManager().beginTransaction().remove(FragA).commit();
getSupportFragmentManager().beginTransaction().remove(FragB).commit();
getSupportFragmentManager().beginTransaction().remove(FragC).commit();

and then attach it again to fragmentManager. if you want to save the stats of fragments use detach() instead of remove. more details is available here

kAvEh
  • 484
  • 4
  • 13