How to check which fragment is running at the moment. To make a condition out of this

66 Views Asked by At

I navigate to other fragments using navigation. And I want to add a condition that if, for example, (profile fragment) is running, then visibility = GONE for the header. Experts help to solve the problementer image description here enter image description here

enter image description here

enter image description here

How to find out which fragment is currently running

1

There are 1 best solutions below

0
On BEST ANSWER

hey you can have a look at the below link to find which fragment is currently visible at a certain time

NavHostFragment navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host);
navHostFragment.getChildFragmentManager().getFragments().get(0);

for more info

Android Navigation Architecture Component - Get current visible fragment