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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.