0

I would like to use NavController.OnNavigatedListener to log destinations changing events. The problem is that when some fragment is saved in backstack than for every navigation change is onNavigated called ones more and destination is that fragment which is saved in backstack. I need to filter this events, but I don't know how. I was trying to find something usefull in destination but I found nothing.

class MyOnNavigatedListener() : NavController.OnNavigatedListener {

override fun onNavigated(controller: NavController, destination: NavDestination) {
//log events
}

}

  • `onNavigated()` is called whenever the destination changes, be it because it is due to a `navigate()` call or from a `popBackStack()` call. Are you saying you want to filter out the events caused by `popBackStack()` like calls? – ianhanniballake Nov 30 '18 at 17:45
  • I don't think so. In my case `onNavigate()` is called twice when destination changes. Once with right destination and once with destination which is fragment inside backstack and that second call is what I want to eliminate or filter. – Radek Špinka Dec 01 '18 at 01:20
  • If that's the case, please [file a bug](https://issuetracker.google.com/issues/new?component=409828&template=1093757) with a sample project that reproduces your issue as that is certainly not expected. – ianhanniballake Dec 01 '18 at 01:26
  • @RadekŠpinka can you provide your full code, especially how you navigating between destinations – Alex Dec 02 '18 at 13:32

1 Answers1

1

in AndroidX

NavController.OnNavigatedListener -> NavController.OnDestinationChangedListener

norbDEV
  • 4,795
  • 2
  • 37
  • 28